Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Would I expect to get MongoError: E11000 duplicate key error index when using collection.save()
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mooky  
View profile  
 More options Nov 2 2012, 6:00 am
From: Mooky <nick.minute...@gmail.com>
Date: Fri, 2 Nov 2012 03:00:40 -0700 (PDT)
Local: Fri, Nov 2 2012 6:00 am
Subject: Would I expect to get MongoError: E11000 duplicate key error index when using collection.save()

I am saving a document thus:

resultsCollection.save(results, {safe: true}, function(err){
....

})

I am getting errors:
MongoError: E11000 duplicate key error index: DB.resultsCollection.
$_id_  dup key: { : ObjectId('50923b9de4b0b8b0e22c3d07') }

Should I get this error when using save() ?

Cheers.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mooky  
View profile  
 More options Nov 2 2012, 6:02 am
From: Mooky <nick.minute...@gmail.com>
Date: Fri, 2 Nov 2012 03:02:35 -0700 (PDT)
Local: Fri, Nov 2 2012 6:02 am
Subject: Re: Would I expect to get MongoError: E11000 duplicate key error index when using collection.save()
Using "version": "1.0.2" of the driver ...

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian Kvalheim  
View profile  
 More options Nov 2 2012, 6:16 am
From: Christian Kvalheim <chris...@gmail.com>
Date: Fri, 2 Nov 2012 11:16:42 +0100
Local: Fri, Nov 2 2012 6:16 am
Subject: Re: Would I expect to get MongoError: E11000 duplicate key error index when using collection.save()
upgrade to latest then try again. you should avoid using save and do partial updates or inserts depending on your need as you'll avoid problems such a two processes changing the same whole document and loosing changes.

On Nov 2, 2012, at 11:02 AM, Mooky <nick.minute...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mooky  
View profile  
 More options Nov 2 2012, 6:25 am
From: Mooky <nick.minute...@gmail.com>
Date: Fri, 2 Nov 2012 03:25:56 -0700 (PDT)
Local: Fri, Nov 2 2012 6:25 am
Subject: Re: Would I expect to get MongoError: E11000 duplicate key error index when using collection.save()
We have had an issue upgrading to the latest for some time - a
connection-related issue we havent been able to reproduce in a limited
example... (if you recall?)

With regard to using collection.save() - it is intended/desired that
the operation is idempotent.
If 2 processes happen to be trying the save the same doc, we are happy
for both operations to succeed because we know the doc in both cases
will be identical. We dont intend for 2 processes to be writing the
same doc - but if it happens due to some race condition, we dont mind
& we dont want 10's of 1000's of errors being logged...

So, was there a known issue with save()?

On Nov 2, 10:16 am, Christian Kvalheim <chris...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mooky  
View profile  
 More options Nov 2 2012, 6:29 am
From: Mooky <nick.minute...@gmail.com>
Date: Fri, 2 Nov 2012 03:29:43 -0700 (PDT)
Local: Fri, Nov 2 2012 6:29 am
Subject: Re: Would I expect to get MongoError: E11000 duplicate key error index when using collection.save()
And to re-ask the question, should it be possible to get a MongoError:
E11000 duplicate key error using save()?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian Kvalheim  
View profile  
 More options Nov 2 2012, 6:35 am
From: Christian Kvalheim <chris...@gmail.com>
Date: Fri, 2 Nov 2012 11:35:00 +0100
Subject: Re: Would I expect to get MongoError: E11000 duplicate key error index when using collection.save()
Collection.prototype.save = function save(doc, options, callback) {
  if('function' === typeof options) callback = options, options = null;
  if(options == null) options = {};
  if(!('function' === typeof callback)) callback = null;

  var errorOptions = options.safe != null ? options.safe : false;
  errorOptions = errorOptions == null && this.opts.safe != null ? this.opts.safe : errorOptions;
  // Extract the id, if we have one we need to do a update command
  var id = doc['_id'];

  if(id) {
    this.update({ _id: id }, doc, { upsert: true, safe: errorOptions }, callback);
  } else {
    this.insert(doc, { safe: errorOptions }, callback && function (err, docs) {
      if (err) return callback(err, null);

      if (Array.isArray(docs)) {
        callback(err, docs[0]);
      } else {
        callback(err, docs);
      }
    });
  }

};

the answer should be no if you look at the code which might mean there is another problem (like some other unique index somewhere)

On Nov 2, 2012, at 11:29 AM, Mooky <nick.minute...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mooky  
View profile  
 More options Nov 2 2012, 6:42 am
From: Mooky <nick.minute...@gmail.com>
Date: Fri, 2 Nov 2012 03:42:08 -0700 (PDT)
Local: Fri, Nov 2 2012 6:42 am
Subject: Re: Would I expect to get MongoError: E11000 duplicate key error index when using collection.save()
Hmmm.

We dont have any other unique index.

We _are_ saving an array of docs with _id's. ie
collection.save([{_id : '50923b81e4b0b8b0e22bfbdd'},{_id :
'50919453e4b045be9d21563b'}])

Looking at the code, that might be the problem?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian Kvalheim  
View profile  
 More options Nov 2 2012, 6:47 am
From: Christian Kvalheim <chris...@gmail.com>
Date: Fri, 2 Nov 2012 11:47:49 +0100
Local: Fri, Nov 2 2012 6:47 am
Subject: Re: Would I expect to get MongoError: E11000 duplicate key error index when using collection.save()
yeah that's not supported, it's only a single document save

On Nov 2, 2012, at 11:42 AM, Mooky <nick.minute...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mooky  
View profile  
 More options Nov 2 2012, 6:56 am
From: Mooky <nick.minute...@gmail.com>
Date: Fri, 2 Nov 2012 03:56:12 -0700 (PDT)
Local: Fri, Nov 2 2012 6:56 am
Subject: Re: Would I expect to get MongoError: E11000 duplicate key error index when using collection.save()
Ok. I see.
Interestingly, it seems to be fine from the mongo console...

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mooky  
View profile  
 More options Nov 2 2012, 6:59 am
From: Mooky <nick.minute...@gmail.com>
Date: Fri, 2 Nov 2012 03:59:41 -0700 (PDT)
Local: Fri, Nov 2 2012 6:59 am
Subject: Re: Would I expect to get MongoError: E11000 duplicate key error index when using collection.save()
Actually, Im talking out my rear ...

On Nov 2, 10:56 am, Mooky <nick.minute...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »