I'm currently facing an issue while updating a field for every Document within a MongoDB collection.
After successfully adding the field from the Mongo shell, I am looking to change the value of each field to a random number.
User.find({}, function(err, items){
if (err){
console.log('err');
console.log(err);
}
items.forEach(function(item){
var time = (Math.floor(Math.random() * (1474893715201 - 1474800000000) + 1474800000000));
item.update({}, {$set:{"lastLogin": time}}, false, true);
});
});
Upon logging each individual 'item' using console.log(item) within the .forEach loop, it retrieves every document in the collection as expected, indicating that everything is functioning smoothly up until this point.
Could anyone identify where I might be making a mistake?
Thank you!