T
T
tikos2015-12-20 16:50:16
MongoDB
tikos, 2015-12-20 16:50:16

How to increment in mongodb?

Here I have such a scheme:

var userSchema = mongoose.Schema({
    urlz : {
            longurl : String,
            shorturl : String,
            clicks : 0
    }   
});

So when I follow the link, I want "clicks ++" to be ie. just find this field and increase by 1, how to implement this in mongodb?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2015-12-20
@lega

db.collection.update(filter, {$inc: {field: 1} })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question