Don't send an error for duplicate unique indexes? [duplicate]










0















This question already has an answer here:



  • How to Ignore Duplicate Key Errors Safely Using insert_many

    1 answer



  • MongoDB Bulk Insert Ignore Duplicate

    1 answer



I have a unique index, because I want mongoDB to ignore any duplicates:



dbo.collection("sold").createIndex( "myId": 1 , unique: true )


However, mongodb treats this as an error, meaning I have to create special error handlign in my application code:



catch(err)
if(err.code === 11000)log(completed: err.result.nInserted, duplicates: err.result.result.writeErrors.length)
elselog( err )



Is there some way to have mongodb not treat duplicates as an error?










share|improve this question













marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 '18 at 0:32


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • "Is there some way to have mongodb not treat duplicates as an error?" - No. A duplicate key error "is what it is". You either code to ignore the specific "expected" error code or "throw" on other unexpected codes, or you go with the overhead of using upserts instead. But you cannot "turn off" how the database basically functions.
    – Neil Lunn
    Nov 12 '18 at 0:35










  • Wil look in to upserts, thanks!
    – Himmators
    Nov 12 '18 at 20:02















0















This question already has an answer here:



  • How to Ignore Duplicate Key Errors Safely Using insert_many

    1 answer



  • MongoDB Bulk Insert Ignore Duplicate

    1 answer



I have a unique index, because I want mongoDB to ignore any duplicates:



dbo.collection("sold").createIndex( "myId": 1 , unique: true )


However, mongodb treats this as an error, meaning I have to create special error handlign in my application code:



catch(err)
if(err.code === 11000)log(completed: err.result.nInserted, duplicates: err.result.result.writeErrors.length)
elselog( err )



Is there some way to have mongodb not treat duplicates as an error?










share|improve this question













marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 '18 at 0:32


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • "Is there some way to have mongodb not treat duplicates as an error?" - No. A duplicate key error "is what it is". You either code to ignore the specific "expected" error code or "throw" on other unexpected codes, or you go with the overhead of using upserts instead. But you cannot "turn off" how the database basically functions.
    – Neil Lunn
    Nov 12 '18 at 0:35










  • Wil look in to upserts, thanks!
    – Himmators
    Nov 12 '18 at 20:02













0












0








0








This question already has an answer here:



  • How to Ignore Duplicate Key Errors Safely Using insert_many

    1 answer



  • MongoDB Bulk Insert Ignore Duplicate

    1 answer



I have a unique index, because I want mongoDB to ignore any duplicates:



dbo.collection("sold").createIndex( "myId": 1 , unique: true )


However, mongodb treats this as an error, meaning I have to create special error handlign in my application code:



catch(err)
if(err.code === 11000)log(completed: err.result.nInserted, duplicates: err.result.result.writeErrors.length)
elselog( err )



Is there some way to have mongodb not treat duplicates as an error?










share|improve this question














This question already has an answer here:



  • How to Ignore Duplicate Key Errors Safely Using insert_many

    1 answer



  • MongoDB Bulk Insert Ignore Duplicate

    1 answer



I have a unique index, because I want mongoDB to ignore any duplicates:



dbo.collection("sold").createIndex( "myId": 1 , unique: true )


However, mongodb treats this as an error, meaning I have to create special error handlign in my application code:



catch(err)
if(err.code === 11000)log(completed: err.result.nInserted, duplicates: err.result.result.writeErrors.length)
elselog( err )



Is there some way to have mongodb not treat duplicates as an error?





This question already has an answer here:



  • How to Ignore Duplicate Key Errors Safely Using insert_many

    1 answer



  • MongoDB Bulk Insert Ignore Duplicate

    1 answer







mongodb






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 '18 at 22:49









Himmators

5,5702685173




5,5702685173




marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 '18 at 0:32


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 '18 at 0:32


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • "Is there some way to have mongodb not treat duplicates as an error?" - No. A duplicate key error "is what it is". You either code to ignore the specific "expected" error code or "throw" on other unexpected codes, or you go with the overhead of using upserts instead. But you cannot "turn off" how the database basically functions.
    – Neil Lunn
    Nov 12 '18 at 0:35










  • Wil look in to upserts, thanks!
    – Himmators
    Nov 12 '18 at 20:02
















  • "Is there some way to have mongodb not treat duplicates as an error?" - No. A duplicate key error "is what it is". You either code to ignore the specific "expected" error code or "throw" on other unexpected codes, or you go with the overhead of using upserts instead. But you cannot "turn off" how the database basically functions.
    – Neil Lunn
    Nov 12 '18 at 0:35










  • Wil look in to upserts, thanks!
    – Himmators
    Nov 12 '18 at 20:02















"Is there some way to have mongodb not treat duplicates as an error?" - No. A duplicate key error "is what it is". You either code to ignore the specific "expected" error code or "throw" on other unexpected codes, or you go with the overhead of using upserts instead. But you cannot "turn off" how the database basically functions.
– Neil Lunn
Nov 12 '18 at 0:35




"Is there some way to have mongodb not treat duplicates as an error?" - No. A duplicate key error "is what it is". You either code to ignore the specific "expected" error code or "throw" on other unexpected codes, or you go with the overhead of using upserts instead. But you cannot "turn off" how the database basically functions.
– Neil Lunn
Nov 12 '18 at 0:35












Wil look in to upserts, thanks!
– Himmators
Nov 12 '18 at 20:02




Wil look in to upserts, thanks!
– Himmators
Nov 12 '18 at 20:02












0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Darth Vader #20

Ondo