Node.js Mongodb更新字符串到目前为止不起作用

Node.js Mongodb更新字符串到目前为止不起作用,node.js,mongodb,date,Node.js,Mongodb,Date,您好,我正在尝试用MongoDB将我所有的JSON文档从string格式(“Fri May 20 09:54:13+0000 2016”)更新为ISODate格式(YYYY-MM-DD HH:MM:SS)。为了实现这一点,我使用了子字符串和一个自制的函数。这工作得很好,我看到控制台按照它应该的样子翻译它 但是当我更新记录时,我看到更新不起作用。我能做些什么使它工作 非常感谢 示例json文档 { "_id" : ObjectId("573edec6ac5e621961f963f2"),

您好,我正在尝试用
MongoDB
将我所有的
JSON
文档从
string
格式(“Fri May 20 09:54:13+0000 2016”)更新为
ISODate
格式(YYYY-MM-DD HH:MM:SS)。为了实现这一点,我使用了子字符串和一个自制的函数。这工作得很好,我看到控制台按照它应该的样子翻译它

但是当我更新记录时,我看到更新不起作用。我能做些什么使它工作

非常感谢

示例json文档

{
  "_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
}
WARNING: db.eval is deprecated
}))

结果

{
  "_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
}
WARNING: db.eval is deprecated


但结果是创建的_at字段没有更新,仍然是一个字符串

最终通过创建一个循环(forEach)来解决问题


这些文件现在看起来像什么?如果代码“不起作用”,您的代码并不能完全帮助我们进行“逆向工程”。不知道
.updateupdate
是什么,这看起来像是打字错误,无论是在你的帖子中还是在你的实际代码中,这都是对“不起作用”的解释。如果你需要帮助的话,你需要更具体地说明什么是不起作用的,并提供足够的信息,以便其他人能够提供帮助。谢谢你的快速回复-Neil Lunn。我用一个json文档的例子改进了我的问题,并删除了typoWell for me
new Date(“Fri May 20 09:54:13+0000 2016”)
returns
ISODate(“2016-05-20T09:54:13Z”)
,这看起来是正确的,并且是您真正需要做的。不是吗?这不起作用-尼尔·伦恩。它一直挂在同一个文件上。我在第一种方法上得到了相同的结果!然后,也许您应该确保键存在并且它实际上是一个字符串
dbTweets.find({“created_at”:{“$type”:2}})
。此外,绝对没有必要在nodejs中编写此代码。就在壳里做吧。你没有正确地使用回调,如果你只是简单地确定日期,那么花时间解释它也不值得。只需从mongo shell运行转换,并使用
newdate()
而不是您自己的自定义函数。