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 :: javascript boolean 
Javascript :: @angular-devkit/build-angular <error 
Javascript :: Error: ENOENT: no such file or directory, lstat ode_modules@react-navigationcoresrcgetStateFromPath.tsx 
Javascript :: sortable jquery 
Javascript :: mongoose patch document 
Javascript :: js if not undefined or null 
Javascript :: array.flat 
Javascript :: get month from timestamp javascript 
Javascript :: save previousdata react 
Javascript :: javascript shift 
Javascript :: get window size on resizing 
Javascript :: to show which tab is active in VueJS 
Javascript :: get node degree networkx 
Javascript :: map method js 
Javascript :: permutation and combination program in javascript 
Javascript :: js compare objects 
Javascript :: mong db connect error 
Javascript :: date format in javascript 
Javascript :: range number in js 
Javascript :: js editable table 
Javascript :: JavaScript Initialize Variables 
Javascript :: scroll up btn 
Javascript :: react useEffect life cycle 
Javascript :: destructured object 
Javascript :: Javascript using for loop to loop through an array 
Javascript :: validate password in nodejs 
Javascript :: nodejs mysql query 
Javascript :: double click on element using javascript 
Javascript :: how to add array object in javascript 
Javascript :: v-bind shorthand 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =