Could you guys tell me what I’m doing wrong ?
I have following document
{
"_id" : ObjectId("5013df3e4a4314271d002476"),
"bgtiled" : NumberLong(1),
"post_count" : NumberLong(0),
"url" : "fb_test",
"url_lower" : "fb_test",
"user_id" : NumberLong(4044217),
"verified" : NumberLong(0)
}
I want to increment post_count. According to documentation I do this
db.users.update({user_id : 4044217}, {$inc : {post_count : 1}});
and it doesn’t increment the field. I also tried this
db.users.update({user_id : 4044217}, {$inc : {"post_count" : 1}});
and this
db.users.update({user_id : 4044217}, {"$inc" : {"post_count" : 1}});
with no result 🙁
If you were doing this in the shell, one way of finding out what is happening would be to check what
getLastError()call returned on this update.Since the shell automatically calls getLastError() for you on every entry, you can do it one of two ways:
Or you can getch the error before the shell calls GLE for you via
note: in the second example, GLE call must be on the same line as the update.
In your case it looks like you would have gotten back information that one existing document was updated, and that might have prompted you to check the find clause of your update statement via
which would have returned more than one document.