I'm trying to pass the results from one MongoDB query to another but the results are in Object and I need it as an Array. Example:
var locId = db.getCollection('locations').find({country:"France"}, {_id:1}).toArray()
How can I pass the results to another query:
db.getCollection('products').find({locId: {$in: locId }})
The results from the first query are something like:
array[1] [
obj[0] {_id: LocId123},
obj[1] {_id: LocId456},
obj[1] {_id: LocId789},
]
I was able to pass the values with this:
locId = Array.from(locId , value => value._id )
The problem is that I cannot encapsulate this in an external function because I cannot pass this "_id" by the function parameters. Any ideas on how to automate it?