6.0.1 • Published 2 years ago

node-lookup-helper v6.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago
const { custom_lookup, custom_unwind} = require('node-lookup-helper');

User Collection Name With - user_collection

_idnameemailstatus
ObjectId("61cc1341089ecb6f5307de6c")Demodemo@demo.comACTIVE

User favourite fruit Collection Name With - user_favourite_collection

_iduser_idfavourite_fruitStatus
ObjectId("61cc1060089ecb6f5307ddc3")ObjectId("61cc1341089ecb6f5307de6c")AppleACTIVE
ObjectId("61b19d0c7aa9361af2d5c747")ObjectId("61cc1341089ecb6f5307de6c")OrangeACTIVE

Get multiple records in array from - user_favourite_collection -

custom_lookup("user_favourite_collection", "_id", "user_id", "user_favourite", ['_id','favourite_fruit'])
const result = await user_collection.aggregate([
    {
        $match: {}
    },
    custom_lookup("user_favourite_collection", "_id", "user_id", "user_favourite", ['_id','favourite_fruit'])
]);

Result:

_id : "61cc1341089ecb6f5307de6c",
name : "Demo",
email : "demo@demo.com",
status : "ACTIVE"
user_favourite : [
	{
		_id : ObjectId("61cc1060089ecb6f5307ddc3"),
		favourite_fruit : "Apple"
	},
	{
		_id : ObjectId("61b19d0c7aa9361af2d5c747"),
		favourite_fruit : "Orange"
	}
]


Get single record in object from - user_favourite_collection -

custom_lookup("user_favourite_collection", "_id", "user_id", "user_favourite", ['_id','favourite_fruit'])

custom_unwind("user_favourite")
const result = await user_collection.aggregate([
    {
        $match: {}
    },
    custom_lookup("user_favourite_collection", "_id", "user_id", "user_favourite", ['_id','favourite_fruit']),
    custom_unwind("user_favourite")
]);

Result:

_id : "61cc1341089ecb6f5307de6c",
name : "Demo",
email : "demo@demo.com",
status : "ACTIVE"
user_favourite : {
	_id : ObjectId("61cc1060089ecb6f5307ddc3"),
	favourite_fruit : "Apple"
}

6.0.1

2 years ago

6.0.0

2 years ago

5.0.0

2 years ago

4.0.0

2 years ago

3.0.0

2 years ago

2.0.0

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago