Hello I am trying to update in MongoDB
all my JSON
documents from a string
format ("Fri May 20 09:54:13 +0000 2016") to a ISODate
format (YYYY-MM-DD HH:MM:SS). To accomplish this I use sub-string and a home made function. This works fine and I see that the console translate it as it should be.
But when I update the records I see the update is not working. What can I do to make it work.
Many Thanks.
sample json document
{
"_id" : ObjectId("573edec6ac5e621961f963f2"),
"contributors" : null,
"truncated" : false,
"text" : "Namens de verenigde marathonschaatsteams: gefeliciteerd @KNSB, @KPN en @Versteegen met het blijvend verbinden van schaatsend Nederland!",
"is_quote_status" : false,
"in_reply_to_status_id" : null,
"id" : NumberLong("733596684547018752"),
"favorite_count" : NumberInt("0"),
"source" : "<a href=\"https://about.twitter.com/products/tweetdeck\" rel=\"nofollow\">TweetDeck</a>",
"timestamp_ms" : "1463738053820",
"in_reply_to_screen_name" : null,
"id_str" : "733596684547018752",
"retweet_count" : NumberInt("0"),
"in_reply_to_user_id" : null,
"favorited" : false,
"geo" : null,
"in_reply_to_user_id_str" : null,
"lang" : "nl",
"created_at" : "Fri May 20 09:54:13 +0000 2016",
"filter_level" : "low",
"in_reply_to_status_id_str" : null,
"place" : null
}
In try thescript based on the advice of the comments on this solution:
Multiply field by value in Mongodb
Update script in Mongobooster
db.eval(function() {
db.STG_LEADS_AUTOSCHADE.find().forEach(function(e) {
e.created_at = new Date(e.created_at);
db.collection.save(e);
});
});
result
WARNING: db.eval is deprecated
But the result is that the created_at field is not updated and is still a string.