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

  • SEARCH
  • Home
  • 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 7785477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:15:44+00:00 2026-06-01T20:15:44+00:00

Could you please tell if it’s possible to get number of inserted documents using

  • 0

Could you please tell if it’s possible to get number of inserted documents using bulk deleted?
For some, reason batchInsert it always returns:
array
‘err’ => null
‘n’ => int 0
‘ok’ => float 1

The code is something like this using mongodb shanty:

$result = Model_Mongodb::insertBatch($importData, array('safe' => true));
  • 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-01T20:15:45+00:00Added an answer on June 1, 2026 at 8:15 pm

    Unfortunately, MongoDB doesn’t return the number of documents inserted by an insert operation. This is a known issue — please see https://jira.mongodb.org/browse/SERVER-4381, and vote for the issue if this is important for your use case.

    However, I will note that if you are using insertBatch with safe mode and you do not get an error result, you may assume that all the documents were inserted successfully.

    EDIT (to answer questions from comments):

    1. By default, a bulk insert stops if there is an error (and returns the error information in the return result). You can override this behavior in MongoDB 2.0+ with the continueOnError flag, in which case the return result will only give information about the last error; any earlier errors will not be reported.

    2. No, you cannot do a bulk upsert. To do an upsert (create if missing, otherwise update), you must use the update method with the upsert flag set to true.

    3. That ticket is not strictly about batchInsert, no — all insert commands currently return n==0 in the getLastError result.

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

Sidebar

Related Questions

Could anyone please tell me how to check what number I've got from a
Could someone please tell me which objects types can be tested using Regular Expressions
Could you please tell me how can I get from CompilerError instance exact text
Could someone please tell me the differences between using a Form, Panel or a
Could you please tell me the logic of using sizeof data / sizeof *data
could anyone please tell me what is wrong this this code? I get a
Could someone please tell me if this is possible in C or C++? void
could please anybody tell us if it is possible and if it is not,
Could someone please tell me what is wrong with the below code? For some
Could anyone please tell me why the following line about filter init method invocation

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.