Re: support for nested localField

From: Asya Kamsky <asya@xxxxxxxxxxx>
To: mongodb-user <mongodb-user@xxxxxxxxxxxxxxxx>
Date: Mon, 25 Apr 2016 20:48:12 -0400
Why ads?
Argument to localField must be a string (which is the name of the
field).  So you will need to transform (via $project) the value you
need into a field and then use that field name in the $lookup.

Something like this:
[ {$project:{ appinfo_user_id: {$arrayElemAt: [ {$arrayElemAt :
["$appinfo.user_ids,0]}, 0]} }},
  {$lookup:{ from:"users", localField:"appinfo_user_id", foreignField:
"_id", as:"userinfo"}} ] )


On Mon, Apr 25, 2016 at 3:38 AM, Astro <andhareatish@xxxxxxxxx> wrote:
Can we use $lookup with nested value for localField?

I have following $lookup stag:

{$lookup:{ from:"users", localField:"appinfo[0].user_ids[0]", foreignField:
"_id", as:"userinfo"}}])

where appinfo is a nested array:

appinfo=[ { name:'xyz', active: true, user_ids=['user1', 'user2', 'user3'] }
]

Any help will be appreciated.

--
You received this message because you are subscribed to the Google Groups
"mongodb-user"
group.

For other MongoDB technical support options, see:
https://docs.mongodb.org/manual/support/
---
You received this message because you are subscribed to the Google Groups
"mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to mongodb-user+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to mongodb-user@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit
https://groups.google.com/d/msgid/mongodb-user/f5658b03-417b-41b6-b138-048ce499fc2a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



-- 
Asya Kamsky
Lead Product Manager
MongoDB
Download MongoDB - mongodb.org/downloads
Free MongoDB Monitoring - cloud.mongodb.com
Free Online Education - university.mongodb.com
Get Involved - mongodb.org/community
We're Hiring! - https://www.mongodb.com/careers

-- 
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
--- 
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to mongodb-user@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CAOe6dJDrtgOPs0AH0zucb5yHTyDii05CqOsn0cNE6p-MgePprw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Why ads?