[SERVER-1222] Insert-or-ignore support Created: 11/Jun/10 Updated: 12/Jul/16 Resolved: 16/Nov/10 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 1.7.3 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Tomasz Wegrzanowski | Assignee: | Eliot Horowitz (Inactive) |
| Resolution: | Done | Votes: | 5 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
If insert is attempted but record with such _id already exists, it's ignored, except for "E11000 duplicate key error index" messages in server logs. It would be nice to be able to indicate that ignoring duplicates is actually intended behavior, to avoid such errors. A related issue is that if a bulk insert is attempted, and any of the _ids already exists, the entire batch fails. This could be covered by the same mechanism of indicating that duplicate _ids should be silently ignored. Support for this option could then be added to mongoimport etc. This is not upsert - no fields in existing records should be overwritten. |
| Comments |
| Comment by Eliot Horowitz (Inactive) [ 16/Nov/10 ] |
|
duplicate key errors no longer show in the log, as its not a system error. |
| Comment by John Wright [ 16/Nov/10 ] |
|
Any word on this or known workarounds? Currently I guess the approach would be to try a bulk insert and if it fails because of a duplicate error, remove the offending record from the batch and try again. Is there another way? |
| Comment by Eliot Horowitz (Inactive) [ 02/Aug/10 ] |
|
That alone won't work in general.
|
| Comment by Terry Smith [ 02/Aug/10 ] |
|
I actually had to solve this issue in our existing install and wanted to share our solution if it's a quick fix for you guys to add: while ( d.moreJSObjs() ) { catch ( AssertionException& e ) { OpDebug& debug = op.debug(); StringBuilder& ss = debug.str; // Assume that one of the inserts failed, but continue so we don't lose the whole batch problem() << " Caught Assertion in " << opToString(op) << " , continuing" << endl; ss << " exception " + e.toString(); mongo::log() << ss.str() << endl; }} |