Mongoose:将mongocollections的date字段增加一个月

我需要根据需要按天,周,月更新一个mongo collection的date字段。 我用下面的代码计算出了一周和一周的情况:

第二天设置:

col.findOneAndUpdate( { _id : item._id } , { $set : { nextRun : new Date(item.nextRun.getTime() + 86400000}} 

下周设置同一天:

 col.findOneAndUpdate( { _id : item._id } , { $set : { nextRun : new Date(item.nextRun.getTime() + (86400000*7))}} 

如何以类似的方式更新月份?

注意:我不希望乘以30,因为如果当前月份有31天,更新后的字段会less一天。

例如,如果该字段的值为2016- 05 -24T11:30:00.000Z,则更新应将其更改为2016- 06 -24T11:30:00.000Z。

尝试了getMonth(),但没有奏效。

添加月份如下:

 var nextRunDate = new Date(item.nextRun); nextRunDate.setMonth(nextRunDate.getMonth() + 1); col.findOneAndUpdate( { _id : item._id }, { $set : { nextRun : nextRunDate } } ); 

更好的方法是使用像时刻这样的date处理库,在那里你可以使用add()方法

 var nextRunDate = moment(item.nextRun).add(1, 'months').toDate(); col.findOneAndUpdate( { _id : item._id }, { $set : { nextRun : nextRunDate } } );