无法将字符串更新为MongoDB中的日期对象4.2

发布于 2025-02-11 12:33:16 字数 488 浏览 0 评论 0原文

我有一个由日期组成的字符串字段,我试图在在mongodb中更新到日期对象的字符串

db.getCollection('rft').updateMany(
  {},[{ "$set": { "createdate": { "$toDate": "$create_date" } }}]
);

获取错误: 错误:无法执行脚本。

错误:更新操作文档必须包含原子操作员 细节: dbcollection.prototype.updatemany@src/mongo/shell/crud_api.js:625:1 @(shell):1:1

有人可以帮助更新记录以随着日期时间获取新字段。

I have a string field which consists of date, I am trying to run following command mentioned in Update string to Date object in mongodb

db.getCollection('rft').updateMany(
  {},[{ "$set": { "createdate": { "$toDate": "$create_date" } }}]
);

Getting an error:
Error: Failed to execute script.

Error: the update operation document must contain atomic operators
Details:
DBCollection.prototype.updateMany@src/mongo/shell/crud_api.js:625:1
@(shell):1:1

Can someone please help in updating the records to get new field with date time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想你只要分分秒秒 2025-02-18 12:33:16

您的查询似乎可以按预期工作,请检查 playgroud 除非预期有所不同...

Your query seems to work as expected , check playgroud unless something different is expected ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文