miércoles, 6 de septiembre de 2017

Mongodb: Insert

Insert

const {MongoClient} = require('mongodb');

const URL = 'mongodb://localhost:27017/<my_app>';

MongoClient.connect(URL, (err, db) => {

if (err) {
return console.log('Unable to connect to mongo db.');
}

console.log('Connected to mongo db.');

db.collection('<my_table>').insertOne({
// Your object
}, (err, result) => {
if (err) {
return console.log('Unnable to insert todo.', err);
}

console.log(JSON.stringify(result.ops, undefined, 2)); // ops stores all the docs inserted
});

db.close();
});


No hay comentarios:

Publicar un comentario