MongoDB - 如何将 6 个月添加到所有文档的特定字段

问题描述

我有一个名为 Posts 的集合,对于每个帖子,我都有一个名为 post_date 的字段,如下所示:

"post_date" : ISODate("2020-02-10T00:00:00Z")

我想通过在每个文档的当前“post_date”上增加 6 个月来更新所有文档。我搜索了这个,但找不到解决方案。有没有办法在 mongo shell 中做到这一点?

提前致谢。

解决方法

我推荐 moment.js 库:

smalllst