Answer the question
In order to leave comments, you need to log in
How to make a connection in Mongo?
Hello! I use MongoDB with Symfony and need a hint, there are two collections:
Collection1: _id, total, card_id, images
Collection2: _id, data, price,
card_id link on collection2 via card_id?
Who knows, tell me, please.
Answer the question
In order to leave comments, you need to log in
I didn’t do exactly this to access from one collection to another not by _id, but apparently so
https://stackoverflow.com/questions/19287142/popul...
Coll1.virtual('card_id', {
ref: 'Coll2',
localField: 'card_id',
foreignField: 'card_id',
justOne: true // for many-to-1 relationships
});
Coll1.find({...})
// if you use select() be sure to include the foreign key field !
.select({ card_id })
// use the 'virtual population' name
.populate('card_id')
.exec(function(err, books) {...})
Collection1.aggregate([{
$lookup:
{
from: "Collection2",
localField: "card_id",
foreignField: "card_id",
as: "from_coll_2"
}
}])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question