Issues with an embedded relationship query in MongoDb -
i need performing query on embedded relationship in mondodb.
i have users collection array list of friends each user. array holds document id key users _id object.
what want return list of friends of users friends information such firstname, lastname, , email. in fact schema looks like.
users schema
_id: objectid(), firstname: string, lastname: string, email: string, friends: [ { id: objectid()}, { id: objectid }, { id: objectid } ]
i think of query similar this:
db.users.aggregate([ { $lookup: { from: 'users', localfield: 'friends.id', foreignfield: '_id', as: 'my_friends'} }, { match: { email: 'someones_email@yahoo.com' }} ])
this looks referenced relationship on same collection rather one. possible?
Comments
Post a Comment