Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongodb insertmany

#simple cli: (u can enhance by error control via inner lambda)

var data = [{"uid":1},{"uid":2}]

db.getCollection("collectionName").insertMany(data)
Comment

mongodb js insertmany

var MongoClient = require('mongodb').MongoClient;
var url = 'mongodb://localhost:27017/test';
var data1={
    name:'Data1',
    work:'student',
    No:4355453,
    Date_of_birth:new Date(1996,10,17)
};

var data2={
    name:'Data2',
    work:'student',
    No:4355453,
    Date_of_birth:new Date(1996,10,17)
};

MongoClient.connect(url, function(err, db) {
    if(err!=null){
        return console.log(err.message)
    }

    //insertOne
    db.collection("App").insertOne(data1,function (err,data) {

        if(err!=null){
            return console.log(err);
        }
        console.log(data.ops[0]);
    });

    //insertMany

var Data=[data1,data2];

db.collection("App").insertMany(Data,forceServerObjectId=true,function (err,data) {

        if(err!=null){
            return console.log(err);
        }
        console.log(data.ops);
    });
    db.close();
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: sending json data uing fetch is empty 
Javascript :: apar chinmoy phy js code 
Javascript :: gojs select node programmatically 
Javascript :: react native azure 
Javascript :: react native swipe screen 
Javascript :: access multiple classes with loop 
Javascript :: return jsx in for loop 
Javascript :: React ES6 Arrow Functions 
Javascript :: map a property from array of objects javascript 
Javascript :: how to add value with useref in react 
Javascript :: jsfuck 
Javascript :: line break in javascript in notification 
Javascript :: this.jsObject.functions is not a function 
Javascript :: js comment 
Javascript :: normal function vs arrow function 
Javascript :: intellij debugger export object as json 
Javascript :: delate char betwen index js 
Javascript :: execcommand image 
Javascript :: html js display pdf file 
Javascript :: Firebase: Error (auth/invalid-api-key). 
Javascript :: json ld product schema 
Javascript :: node_modules/react-native-paper/lib/module/core/Provider.js 
Javascript :: sequelize find deleted 
Javascript :: e.target.id not working react js 
Javascript :: dynamic array of months js 
Javascript :: merge in mongodb 
Javascript :: opacity material ui 
Javascript :: alert message 
Javascript :: latex sum two lines subscript 
Javascript :: ckeditor 5 on blur 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =