0

I know there are stackoverflow posts on updating mongodb sting date to iso date but i could not find how to do in nested field. my json structure is like this:

{  
    "_id" : "588885445",  
    "data" : {  
        "team" : "abc",  
        "subteam" : "123",  
        "datetime" : "2018-05-20 11:47:01",  

   }  
}  

i need to change date string to iso date. This is what I am trying but its not working.

var cursor = db.getCollection('log').find({}) ;  
while (cursor.hasNext()) {   
var doc = cursor.next();   
db.members.update({_id : doc._id}, {'$set' : {"data.datetime" : new ISODate('data.datetime') }});  
}
Gagan Deep
  • 89
  • 1
  • 10
  • `new ISODate(doc.data.datetime)`. Full path and no quotes for a JavaScript object. Also `new Date(doc.data.datetime)` is the same thing as `ISODate()` is really just a shell "alias" for the same function and used to denote fields with BSON Date. – Neil Lunn May 28 '18 at 06:51
  • it says "Updated 0 record(s) in 617ms" but date hasnt been updated. its still string. – Gagan Deep May 28 '18 at 06:53
  • Read the linked answer. That is what it is there for. – Neil Lunn May 28 '18 at 06:56

0 Answers0