5

I have this two mongo commands, that in my opinion should lead to the same results:

for(var i=0;i<1000;i++){db.test.insert({a:1}); db.getLastError({j:1, w:1});};

for(var i=0;i<1000;i++){db.test.insert({a:1}); db.runCommand({getLastError:1, j:1, w:1});};

both commands perform inserts correctly, however, the second one is cca 100x times slower (500ms vs 45s). Does anybody know, why this is so? The difference is present only when {j:1} is set, so it's probably somehow related to some journaling issues?

Tomas Kulich
  • 14,388
  • 4
  • 30
  • 35
  • just curious - what happens when fsync is set to true? Is journaling enabled? – ali haider Dec 20 '13 at 16:25
  • fsync does not change anything (at least for me). I have MongoDB at version 2.4.8 and I did not change the default options for journaling, so it should be enabled. – Tomas Kulich Dec 20 '13 at 16:42

1 Answers1

1

The second command is actually waiting for the journal commit whereas the first is not and hence the difference. When using the getLastError shell helper you cannot pass in the j option. It should be a number or string corresponding to the w parameter to the getlasterror database command as documented here.

  • Thanks for the answer, it helped me a lot. Do you know, whether this information is available somewhere in the documentation? (getLastError section is ok, but says nothing about using getLastError as a shell helper) – Tomas Kulich Dec 24 '13 at 13:51