Tuesday 6 June 2017

Unable to insert records using insertMany using compose for mongodb

I am using nodejs to connect and insert records in compose for mongodb.I am getting the below error when I try to use insertMany and save records.

(node:10140) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoError: Writes to conf ig servers must have batch size of 1, found 23

Below is my code snippet:

MongoClient.connect(url, function(err, db) {

if(err){
console.log('Error is ' + err);
}
else{
 console.log("Connected correctly to server");
try {
var col = db.collection('offshift');
    col.insertMany(result).then(function(result){
     res.json({message:'Data saved succesfully!',error_code:0, data: result});
   });

} catch (e) {
   console.log(e);
}
 db.close();
}

});



via Monesh

No comments:

Post a Comment