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 8994789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:30:28+00:00 2026-06-15T23:30:28+00:00

I asked myself, whether javascript (concerning mongoDB) waits for the execution of mongoDB processes.

  • 0

I asked myself, whether javascript (concerning mongoDB) waits for the execution of mongoDB processes.

For example:

Im inserting documents like

for (i=0; i<=myarray.length -1; i++)
{
        db.mycol.insert(myarray[i]);
}

If I check the col status directly after that only see a few documents in the db or even 0. (e.g. instead of 100 only 29 or 0). When I execute the sleep() function with e.g. sleep(10000) I can see all may inserted documents.

So my question is, how can I make sure, that javascript waits for the complete insert? Or how can I measure that? At the moment I’m using

start = new Date().getTime();

for (i=0; i<=myarray.length -1; i++)
{
        db.mycol.insert(myarray[i]);
}
end = new Date().getTime();
time = end - start;

But if the insert-process isn’t completed, the measurement of that function seems senseless to me.

edit:

by using db.getLastError({w:1});

I receive to following error:

uncaught exception: getlasterror failed: {
“singleShard” : “replica2/ip:port,ip:port”,
“n” : 0,
“lastOp” : NumberLong(“5824731790958395692”),
“connectionId” : 111744,
“assertion” : “wrong type for field (w) 3 != 2”,
“assertionCode” : 13111,
“errmsg” : “db assertion failure”,
“ok” : 0
}
failed to load: … myscript.js

  • 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-15T23:30:28+00:00Added an answer on June 15, 2026 at 11:30 pm

    If you want to wait until MongoDB has written the data you can call getLastError with whatever options you’re looking to wait for.

    Like this:

    start = new Date().getTime();
    for (i=0; i<=myarray.length -1; i++) {
        db.mycol.insert(myarray[i]);
    }
    db.getLastError({w:1});
    end = new Date().getTime();
    time = end - start;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A while ago I asked myself, when I write something like this: char* first(int
I've asked this question before but I don't think I explained myself clearly so
Alright, I know questions like this have probably been asked dozens of times, but
I've always asked myself this question, particularly when i see how JPA 2.0 metamodel
I always asked myself if it would be possible to make a Java to
this is more a theoretical question i asked myself. I remembered that BinarySearch of
Designing a web application with ASP.NET MVC I asked myself how can I also
Over the years I've often asked myself why game developers place many small images
I was actually asked this myself a few weeks ago, whereas I know exactly
I am getting into testing in python and I asked myself how to test

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.