Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

mongodb check if collection exists

db.collectionNames(collName, function(err, names) {
    console.log('Exists: ', names.length > 0);
});

// MongoDB 2.x:
db.listCollections({name: collName})
    .next(function(err, collinfo) {
        if (collinfo) {
            // The collection exists
        }
    });
Source by www.edureka.co #
 
PREVIOUS NEXT
Tagged: #mongodb #check #collection #exists
ADD COMMENT
Topic
Name
7+9 =