Compare two fields from different MongoDB Collections

552 views
Skip to first unread message

Jeffery B.

unread,
Jan 26, 2016, 2:36:17 AM1/26/16
to mongodb-user
  • Is there a way to compare two fields from different MongoDB Collections? I have a 2 collections: collection_1:
    {
    "english" : {
    "orth" : "africa",
    "pron" : "æfrikə"  
    },
     "francais" : {
     "orth" : "afrique"
    }
    } collection_2: {

    "form" : {

    "orth" : "afrique",

    "pron" : "afʀik"

    }

    "sense" : { "cit" : { "quote" : "africa" } }  
    } I would like to find all where "collection_1.english.orth" == "collection_2.form.orth" and copy/add "form.pron" from collection_2 into collection_1 under "francais.pron". 
    Any help would be greatly appreciated...
    Thanks,
    Jeffery

Hakan

unread,
Jan 26, 2016, 3:31:18 AM1/26/16
to mongodb-user
For the first approach, have you looked at the $lookup stage https://docs.mongodb.org/manual/reference/operator/aggregation/lookup/

You need at least 2 application-level operations for your second approach.

Jeffery B.

unread,
Feb 1, 2016, 1:31:30 PM2/1/16
to mongodb-user
Thanks Hakan, that helped...
Reply all
Reply to author
Forward
0 new messages