Don't send an error for duplicate unique indexes? [duplicate]
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?
mongodb
marked as duplicate by Neil Lunn
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.
add a comment |
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?
mongodb
marked as duplicate by Neil Lunn
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
add a comment |
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?
mongodb
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
mongodb
asked Nov 11 '18 at 22:49
Himmators
5,5702685173
5,5702685173
marked as duplicate by Neil Lunn
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
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
add a comment |
"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
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
"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