mongodb check if collection exists code example
Example: 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
}
});