0 votes
in MongoDB by
What does an appropriate db.ClockTime.update() statement look like to convert these text based values to a date datatype in MongoDB?

1 Answer

0 votes
by
This code should do it:

> var cursor = db.ClockTime.find()

> while (cursor.hasNext()) {

… var doc = cursor.next();

… db.ClockTime.update({_id : doc._id}, {$set : {ClockInTime : new Date(doc.ClockInTime)}})

… }

I have exactly the same situation as Jeff Fritz.

In my case I have succeed with the following simpler solution:

db.ClockTime.find().forEach(function(doc) {

doc.ClockInTime=new Date(doc.ClockInTime);

db.ClockTime.save(doc);

})

Related questions

0 votes
asked Jun 8, 2023 in Agile by Robindeniel
+1 vote
asked Jan 27, 2022 in Usability Principles by sharadyadav1986
...