skip to Main Content

MongoDB Aggregation – Fetch data from ObjectId subarray

I have these collections: author [ { _id: "63c242130b17d5516e0cb499", author_name:'Vyom', book_ids:["63c242330b17d5516e0cb49a","63c242410b17d5516e0cb49b"] } ] book [ { _id:"63c242330b17d5516e0cb49a", author_id:'63c242130b17d5516e0cb499', book_name:'True Love', genere:'horror' }, { _id:"63c242410b17d5516e0cb49b", author_id:'63c242130b17d5516e0cb499', book_name:'Monster Strike', genere:'romance' }, ] I want to fetch details of books in author collection…

VIEW QUESTION

MongoDB shell: how to remove all collections except list

I would like to remove all collections except a list. db.getCollectionNames().forEach(function(n){db[n].remove({})}); will remove all collections. db.getCollectionNames().filter(function(collection){return! /^((keepthisone)|(andthisone)|(alsokeepthisone))$/.test(collection)}); will list all the collections, except the ones I want to keep. How do I combine the two? db.getCollectionNames().filter(function(collection){return! /^((keepthisone)|(andthisone)|(alsokeepthisone))$/.test(collection)}).forEach(function(n){db[n].remove({})}); Does nothing.

VIEW QUESTION
Back To Top
Search