[SERVER-7033] Provide details about successes and errors in bulk insert in getLastError Created: 13/Sep/12  Updated: 10/Dec/14  Resolved: 02/Apr/13

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

Type: Improvement Priority: Major - P3
Reporter: Scott Hernandez (Inactive) Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-4381 getLastError returns n:0 after insert... Closed
Related
related to SERVER-9038 New write operation method for insert... Closed
is related to SERVER-1699 Fill in _id value for inserted docs Closed
Participants:

 Description   

Currently we don't return the number of docs inserted, or the number that error'd out, or, in the continueOnError case, a list of errors.

> db.test1.insert([{_id:1}, {_id:1}, {_id:1}]); db.getLastErrorObj()
{
	"err" : "E11000 duplicate key error index: github.test1.$_id_  dup key: { : 1.0 }",
	"code" : 11000,
	"n" : 0,
	"connectionId" : 1,
	"ok" : 1
}
 

We should set "n" to successful docs inserted, and nFailures to the number of failed insertions (1 if continueOnError is false).

In addition we should return an errorDocs field like this:

errorDocs: [
   {_id:1, err:"..."},
   {_id:1, err:"..."},
   {_id:1, err:"..."},
]

So the client will know which docs failed on the insert.



 Comments   
Comment by Eliot Horowitz (Inactive) [ 02/Apr/13 ]

will be part of SERVER-9038

Comment by Eliot Horowitz (Inactive) [ 15/Sep/12 ]

Not sure if this is the right direction.

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