insertStandings(standings,options){ try{ return this.standings.insertMany(standings, options); }catch(err){ console.error(err); } }
async function initializeDB() { const db = await connectDB(); const user = await db.collection('users').findOne({ id: 'U1' }); if (user) { return; } for (let collectionName in defaultState) { let collection = db.collection(collectionName); await collection.insertMany(defaultState[collectionName]); } }
//Para meter datos mongoClient.connect(url, (error, db) => { if (error) throw error; const dbName = db.db("nodeJSExample"); const myObj = [{name: 'Santiago', age: 21}, {name: 'Jesus', age: 22}, {name: 'Santy', age: 18}, {name: 'Chuy', age: 16}, {name: 'Sebastian', age: 16},]; dbName.collection("clients").insertMany(myObj, (error, res) => { if (error) throw error; console.log('Docs inserted!'); db.close(); }); });
MongoClient.connect(url, { useUnifiedTopology: true }).then(con => { const db = con.db(db_name); console.log(`Connection extablished to ${db_name}.`); db.collection('posts').drop().then(delOK => { if (delOK) console.log("Collection deleted"); }).then(() => { return db.collection('posts').insertMany(mockPosts); }).then(res => { // console.log(res); if (res.result.ok && res.insertedCount === 1) { console.log(`Blog post with ID=${res.insertedId} was successfully created.`); } }).then(() => { return db.collection('posts').find().toArray(); }).then(posts => { console.log(posts); }).catch(err => { console.error(err); }).finally(() => { con.close(); }); }).catch(err => console.error(err));
MongoClient.connect(url, { useNewUrlParser: true, useUnifiedTopology: true }, (err, client) => { if (err) { console.error('Unable to connect to MongoDB server'); } console.log('Connected to MongoDB server'); const db = client.db('autocomplete'); db.collection('rooms').insertMany(rooms, err => { if (err) { console.log('Unable to insert seed data.'); } else console.log('Seed data succesfully initiated.'); }); client.close(); });
const collection = db.collection('test') collection.insertMany([{ a: 1 }, { a: 2 }, { a: 3 }], { w: 1 }, function (err, results) { t.error(err, 'no insert error') t.strictEqual(results.result.n, 3, 'inserted three records')
async function demo() { try { const con = await MongoClient.connect(url, { useUnifiedTopology: true }); try { const db = con.db(db_name); console.log(`Connection extablished to ${db_name}.`); const delOK = await db.collection('posts').drop(); if (delOK) console.log("Collection deleted"); const insertedRes = await db.collection('posts').insertMany(mockPosts); if (insertedRes.result.ok && insertedRes.insertedCount === 1) { console.log(`Blog post with ID=${insertedRes.insertedId} was successfully created.`); } const posts = await db.collection('posts').find().toArray(); console.log(posts); return posts; } catch (err) { console.error(err); } finally { con.close(); } } catch (err) { console.error(err) } }
db.collection('contests').insertMany([ { id: 1, categoryName: 'Business/Company', contestName: 'Cognitive Building Bricks', description: ` ]).then(response => { console.info('Contests', response.insertedCount); db.collection('names').insertMany([ { id: 101, name: 'Mind Assembly', timestamp: new Date() }, { id: 102, name: 'Brain Scaffold', timestamp: new Date() },
db.collection('orders').drop() .then(dropRes => { db.collection('orders').insertMany(orders) .then(res => { if (err) throw err;
async function demo() { try { const con = await MongoClient.connect(url, { useUnifiedTopology: true }); try { const db = con.db(db_name); console.log(`Connection extablished to ${db_name}.`); try { const delOK = await db.collection('users').drop(); if (delOK) console.log("Collection deleted"); } catch (err) { console.error(err); } finally { const insertedRes = await db.collection('users').insertMany(mockUsers); if (insertedRes.result.ok && insertedRes.insertedCount === 1) { console.log(`Blog post with ID=${insertedRes.insertedId} was successfully created.`); } const users = await db.collection('users').find().toArray(); console.log(users); return users; } } catch (err) { console.error(err); } finally { con.close(); } } catch (err) { console.error(err) } }
await otherColl.insertMany([ await otherColl.insertMany([ await otherColl.insertMany([ await otherColl.insertMany([ await otherColl.insertMany([
db.collection('products').insertMany(products, function (err, res) { if (err) throw err; if (res.insertedCount >= 1) {
MongoClient.connect(url, { useNewUrlParser: true, useUnifiedTopology: true }, (err, client) => { if (err) { console.error('Unable to connect to MongoDB server'); } console.log('Connected to MongoDB server'); const db = client.db('autocomplete'); db.collection('rooms').insertMany(rooms, err => { if (err) { console.log('Unable to insert seed data.'); } else console.log('Seed data succesfully initiated.'); }); client.close(); });