Raggamuffin
Raggamuffin

Reputation: 709

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

I have an image gallery with a forward and backward-button. on a click on either of the buttons i want to upsert an entry in the local database with the times the image has been viewed (so i can later see which image has been viewed the most).

When i use:

'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
        }
    });

}

Problem: 'timesViewed' does only increase on the insertion in the database.

Question: How can i make this query increase the value of 'timesViewed' with every click event?

Thanks for your help!

Muff

Upvotes: 0

Views: 325

Answers (1)

Alex Polkhovsky
Alex Polkhovsky

Reputation: 3360

Remove timesViewed from $setOnInsert

Upvotes: 1

Related Questions