0

I have simple query that results with array:

db.getCollection('myCollection')
    .find( {
               _id: '5c1286ed222a6e0e4acbd018'
           }, 
           {
               myProperty: 1, 
               _id: 0 
           })

Result:

{
    "myProperty" : [ 
        "5c1286ed222a6e0e4acbd017"
    ]
}

I want to query another collection with this result. The other collection (let call it yourCollection) has property 'yourProperty' which is the same kind of array like the result.

db.getCollection('scene').find({
// all the objects where 'yourProperty' contains at least one element of
// the first query result.
'yourProperty': containsAny() //Something like that
})

My goal is to get all elements of 'yourCollection' where its property 'yourProperty' has at least one element that is resulted with first query above.

eomeroff
  • 9,599
  • 30
  • 97
  • 138
  • Try using the $lookup from MongoDB aggregation framework. https://stackoverflow.com/questions/5681851/mongodb-combine-data-from-multiple-collections-into-one-how. – Mani Mar 04 '19 at 19:49
  • Possible duplicate of [MongoDB: Combine data from multiple collections into one..how?](https://stackoverflow.com/questions/5681851/mongodb-combine-data-from-multiple-collections-into-one-how) – Mani Mar 04 '19 at 19:50

0 Answers0