Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9018673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:35:21+00:00 2026-06-16T04:35:21+00:00

Could you guys tell me what I’m doing wrong ? I have following document

  • 0

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 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:35:23+00:00Added an answer on June 16, 2026 at 4:35 am

    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:

    > db.users.update({user_id : 4044217}, {$inc : {post_count : 1}})
    > db.getPrevError()
    { "err" : null, "updatedExisting" : true, "n" : 1, "nPrev" : 8, "ok" : 1 }
    

    Or you can getch the error before the shell calls GLE for you via

    > db.users.update({user_id : 4044217}, {$inc : {post_count : 1}}); db.getLastErrorObj();
    {
        "updatedExisting" : false,
        "n" : 0,
        "connectionId" : 2,
        "err" : null,
        "ok" : 1
    }
    

    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

    > db.users.find( {user_id : 4044217} )
    

    which would have returned more than one document.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys could anyone tell me what's wrong am I doing here? Below are four
Could you guys please tell me how I can make the following code more
Hi guys could anyone tell me where im going wrong? The basic aim of
Ok guys, could you tell me is there a certain bug in current code:
Hey guys i have looked as much as i could and i could not
i have a sample str1 14 girls str2 178 guys i tried the following
Could you guys tell me why xdebug never stops on single-line statements ? I'm
Hello there fellow Stackers! I wonder if anybody could tell me what the following
I have not submitted an application yet, however am wondering if you guys could
hi guys even i have success delete the message return false delete message(could not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.