Meteor Mongo-将$inc与upstart一起使用不会增加价值

Meteor Mongo - using $inc with upsert does not increase Value

本文关键字:增加 一起 Mongo- inc upstart Meteor      更新时间:2024-06-02

我有一个带有向前和向后按钮的图像库。点击任意一个按钮,我想在本地数据库中添加一个条目,显示图像被查看的时间(这样我以后就可以看到哪个图像被查看得最多)。

当我使用:

'click .btn-forward, click .btn-backward' (event, template) {
Local.Viewed.upsert({
        imageId: this._id
    }, {
        $setOnInsert: {
            imageId: this._id,
            imageName: this.name,
            timesViewed: 0
        },
        $inc: {
            timesViewed: 1
        }
    });
}

问题:"timesViewed"只会在插入数据库时增加。

问题:如何使此查询增加每次单击事件的"timesViewed"值?

谢谢你的帮助!

Muff

从$setOnInsert 中删除查看的时间