Replies: 1 comment
-
$lookup always returns an array, you would need an extra |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I greet everyone Happy New Year in advance. Please I have this mongoose aggregate that returns the right records but do not include fields in the lookup collection i.e referenced collection.
******THIS IS MY SCHEMAS
===============USERS COLLECTION
const Users = mongoose.model('User', usersSchema);
module.exports = Users;
===============MOTORS COLLECTION
*******WHAT I WANT TO ACHIEVE
The query worked but does not work as perfectly. It doesn't include the fullname and email of the referenced Collection using the field mentioned.
I want to achieve two things,
1.) I want to pull the user details(fullname and email) from the Users collection using the garrage_of_origin_user field in the Motors schema collection. The query worked but the fullname and email are null i.e they were not pulled.
How do I pull details(fullname and email) of the users in the subdocument sub_origin_garrage array object which are "sub_garrage_user1" and "sub_garrage_user2" fields? Note that there are users in the subdocuments(sub_origin_garage) too. How do i use lookup to pull out the fields in the users collection for this 3 users i.e garrage_origin_user, sub_garrage_user1 and sub_garrage_user2 in one document?
*******THIS IS MY CODE
I will appreciate your kind assistance.
Beta Was this translation helpful? Give feedback.
All reactions