Answers for "mongodb check if collection exists"

0

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
        }
    });
Posted by: Guest on April-28-2021

Code answers related to "mongodb check if collection exists"

Code answers related to "Javascript"

Browse Popular Code Answers by Language