classExists(name) { return this.connect().then(() => { return this.database.listCollections({ name: this._collectionPrefix + name }).toArray(); }).then(collections => { return collections.length > 0; }).catch(err => this.handleError(err)); }
init() { mongoose.connection.db.listCollections({name: 'customers'}) .next((err, collinfo) => { if (!collinfo) { console.log('Starting dbSeeder...'); this.seed(); } }); }
testMongo(data) { const mongoString = assembleMongoUrl(data); return mongoose.connect(mongoString, { useNewUrlParser: true, useUnifiedTopology: true }) .then((connection) => { return connection.connection.db.listCollections().toArray(); }) .then((collections) => { return Promise.resolve({ success: true, collections }); }) .catch((err) => Promise.reject(err.message || err)); }
connection.on('open', function () { connection.db.listCollections({name: 'cabs'}).next(function(err, collinfo) { // it will check cabs collection exist or not, if not will create if (collinfo) { console.log(collinfo); } else { console.log(collinfo); populateDB(); } }); });
csv() .fromFile(`./public/data/${image.name}`) .then(function(jsonArrayObj){ //when parse finished, result will be emitted here. mongoose.connection.db.listCollections({name: 'students'}) .next(function(err, collinfo) { if (collinfo) { mongoose.connection.db.dropCollection('students', function(err, result) { jsonArrayObj.forEach(element => { student.create(element) }); }); }else{ jsonArrayObj.forEach(element => { student.create(element) }); } }); })
const mflixCollections = await mflixDB.listCollections().toArray() const actualCollectionNames = mflixCollections.map(obj => obj.name) const expectedCollectionNames = [