6.0.1 • Published 3 years ago
node-lookup-helper v6.0.1
const { custom_lookup, custom_unwind} = require('node-lookup-helper');
User Collection Name With - user_collection
_id | name | status | |
---|---|---|---|
ObjectId("61cc1341089ecb6f5307de6c") | Demo | demo@demo.com | ACTIVE |
User favourite fruit Collection Name With - user_favourite_collection
_id | user_id | favourite_fruit | Status |
---|---|---|---|
ObjectId("61cc1060089ecb6f5307ddc3") | ObjectId("61cc1341089ecb6f5307de6c") | Apple | ACTIVE |
ObjectId("61b19d0c7aa9361af2d5c747") | ObjectId("61cc1341089ecb6f5307de6c") | Orange | ACTIVE |
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
3 years ago
6.0.0
3 years ago
5.0.0
3 years ago
4.0.0
3 years ago
3.0.0
3 years ago
2.0.0
3 years ago
1.1.9
3 years ago
1.1.8
3 years ago
1.1.7
3 years ago
1.1.6
3 years ago
1.1.5
3 years ago
1.1.4
3 years ago
1.1.3
3 years ago
1.1.2
3 years ago
1.1.1
3 years ago
1.1.0
3 years ago
1.0.10
3 years ago
1.0.9
3 years ago
1.0.8
3 years ago
1.0.7
3 years ago
1.0.6
3 years ago
1.0.5
3 years ago
1.0.4
3 years ago
1.0.3
3 years ago
1.0.2
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago