Hey everyone, I want to search through several collections on Mongo Realm and output the result in an array. I used the following function:
exports = function(amounts, colls){
const query = { "amount": { $all: amounts } };
const projection = { "name": 1 };
// Accessing a mongodb service:
var db = context.services.get("mongodb-atlas").db("App");
var doc = [];
var i;
for(i of colls){
doc.push(db.collection(i).find(query,projection).toArray());
}
// return the names
return doc;
};
With exports([“e”, “b”, “z”, “m”], [“CollA”, “CollB”]) in the console I get arrays in an array:
[
[{"_id":{"$oid":"5f7b4ad6513f671c7e11a350"},"name":"Marmor"},
{"_id":{"$oid":"5f7b4ae1513f671c7e11aa05"},"name":"Sand"}],
[{"_id":{"$oid":"5f7b4aaa513f671c7e118bc3"},"name":"Kaese"},
{"_id":{"$oid":"5f7b4ab7513f671c7e11922e"},"name":"Mandel"}]
]
How do I have to change the code to get only one array like below? So far all my attempts have failed.
[
{"_id":{"$oid":"5f7b4ad6513f671c7e11a350"},"name":"Marmor"},
{"_id":{"$oid":"5f7b4ae1513f671c7e11aa05"},"name":"Sand"},
{"_id":{"$oid":"5f7b4aaa513f671c7e118bc3"},"name":"Kaese"},
{"_id":{"$oid":"5f7b4ab7513f671c7e11922e"},"name":"Mandel"}
]
Any help on this one would be greatly appreciated.
Regards,
Axel