0

I am trying to populate array of id's in aggregation method using $lookup in mongoose. I am using mongoose 6.6.2. Here is how I am storing data in mongoDB enter image description here

and this is the query I am using

await mongoose.models.xyz.aggregate([ { $lookup: { from: '$dietaries', localField: 'dietaries', foreignField: '_id', as: 'dietaries' } } ]); 

I am getting empty array as return.

1 Answer 1

2

I'm guessing the problem is with this line from: '$dietaries'

If your collection is named "dietaries", it should be from: 'dietaries'. You don't need the $ there.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.