Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDB 批量修改某一时刻之后创建的文档 #168

Closed
Dream4ever opened this issue Jul 26, 2021 · 0 comments
Closed

MongoDB 批量修改某一时刻之后创建的文档 #168

Dream4ever opened this issue Jul 26, 2021 · 0 comments
Labels

Comments

@Dream4ever
Copy link
Owner

解决过程

Google 搜索关键词:mongodb update documents createdat later than

第一个搜索结果 return query based on date 中给出了参考方法,可以用 $gte 之类的命令,来筛选出符合时间要求的文档。

db.gpsdatas.find({"createdAt" : { $gte : new ISODate("2012-01-12T20:15:31Z") }})

然后再查看 $gt 命令的 官方文档,给出了自己几乎可以直接使用的命令:

db.inventory.update(
   { "carrier.fee": { $gt: 2 } },
   { $set: { price: 9.99 } },
   { multi: true }
)

结合上面两段示例代码,就能够在 MongoDB 中批量修改某个时刻之后创建的所有文档了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant