[SERVER-10354] db.getLastError() always returns null when using autocomplete Created: 26/Jul/13  Updated: 02/Jun/17  Resolved: 02/Jun/17

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Andrew Guo Assignee: DO NOT USE - Backlog - Platform Team
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File m1.PNG     PNG File m2.PNG     Text File mylog.txt    
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

db.test.insert({_id:1})
db.test.insert({_id:1})
db.getLastError()

Participants:

 Description   

I use Mongodb 2.4.5 for windows(32bit). The db.getLastError() always returns null even if an error occurs, but only when using auto-complete for the "getLastError" call.



 Comments   
Comment by Andrew Morrow (Inactive) [ 02/Jun/17 ]

Most uses of getLastError are now obviated by newer write mechanisms, so it does not make sense to invest effort in repairing this edge case. If this is still an issue in practice, avoid using tab completion.

Comment by Eric Daniels (Inactive) [ 02/Aug/13 ]

This error is caused by using autocomplete on a DB object. Since getCollectionNames() is called, it will set the last error to nothing if it succeeds which it does. The problem is storing the last error before calling this and then restoring it as there exists no way to do this currently. An alternative is to temporarily create a new connection for the autocomplete which will have its own getLastError context.

Comment by Daniel Pasette (Inactive) [ 02/Aug/13 ]

i'm able to repro this on all versions and osx as well by using the autocomplete described by mirao.

Comment by Jaromir Obr [ 27/Jul/13 ]

The issue happens to me if I'm using autocomplete in mongo shell

Steps to reproduce:
> db.test.insert(

{ _id : 1, a : 1 }

)
> db.test.insert(

{ _id : 1, a : 1 }

)
E11000 duplicate key error index: test.test.$id dup key: { : 1.0 }

Type the command db.getLastError(), do not use shell autocomplete:
> db.getLastError()
E11000 duplicate key error index: test.test.$id dup key: { : 1.0 }

Type the command, use autocomplete:
> db.getL
press TAB + () + Enter

Expected result:
> db.getLastError()
E11000 duplicate key error index: test.test.$id dup key: { : 1.0 }

Actual result:
> db.getLastError()
null

Used SW:
MongoDB 2.4.5, Ubuntu 13.04 x64

Generated at Thu Feb 08 03:22:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.