i have a database with Mongodb , that contains 13 collections and i want to do a find function on it to get all the documents in that 13 collections in one command if it's possible , for info , i am working with mongoose & node expressjs
Asked
Active
Viewed 823 times
1 Answers
0
There is no way to get all the data from all the collections since queries run on the collection, not outside it. You could however run a loop to get the response from each collection and then consolidate it finally. Perhaps add the results of each collection to a data structure? Something like this -
var dataFromAllCollections = [];
const collections = db.getCollectionNames();
for(var i = 0; i< collections.length; i++){
dataFromAllCollections.push(db.getCollection(collections[i]).find());
}

Sashi
- 2,659
- 5
- 26
- 38