I am trying update a bulk of data in Mongo DB. Here is what I am trying to do:
var bkdet = db.library.find();
bkdet.forEach(function(item){
//process item
var rentDateWithoutTimestamp = item.book.rentDate;
if(rentDateWithoutTimestamp!=null){
var dt = rentDateWithoutTimestamp.split(" ");
print(dt[0]+"" +item._id);
db.library.update({"_id": item._id}, {$set: {"book.rentDate": dt[0]}});
}
})
Weird part is, it only updated around 3000 records.
Initially I tried:
db.library.update({"_id": item._id}, {$set: {item.book.rentDate": dt[0]}});
It printed the log that it updated 1 existing record, but no data change happened. That is when I tried by removing item. from item.book.rentDate and it did not complete all the records as expected.