Home > Mobile >  Mongo DB show all collections except one
Mongo DB show all collections except one

Time:02-10

in Mongo DB how can I retrieve all documents except one which is Test

my code shows all the documents

db.getCollectionNames().forEach(function(collection) { 
    var result = db[collection]; 
    if(result != 'Test') { 
        print("All the documents: "   " for collection: "  collection);
    } 
});

CodePudding user response:

The correct is:

  db.getCollectionNames().forEach(function(collection){
     if(collection != 'Test') {
         print("All the documents: "   " for collection: "  collection);
        }
       }
      );
  • Related