skip to content
Alvin Lucillo

Multiple collections query

/ 1 min read

In mongosh, you can query multiple collections with by iterating an array:

["collection1", "collection2", "collection3", "collection4"].forEach((c) => {
	print("\n== " + c + " ==");
	db.getCollection(c)
		.find({})
		.limit(10)
		.forEach((doc) => printjson(doc));
});