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
Combining documents from two separate collections. Duplicate ids issue.
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
  8 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
 
kumar  
View profile  
 More options May 12 2012, 5:01 pm
From: kumar <kumar.a...@gmail.com>
Date: Sat, 12 May 2012 14:01:56 -0700 (PDT)
Local: Sat, May 12 2012 5:01 pm
Subject: Combining documents from two separate collections. Duplicate ids issue.

Hi All,

I am going to combine documents from two separate collections.
I will do using mongodump and mongorestore. commands.

There may be a chance of having same auto generated Id in both
collections.
Will combine operation (using mongo restore) happen properly due to
same auto generated Id?

Thanks.
Kumar


 
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.
Raxit Sheth  
View profile  
 More options May 12 2012, 5:09 pm
From: Raxit Sheth <raxitsheth2...@gmail.com>
Date: Sun, 13 May 2012 02:39:38 +0530
Local: Sat, May 12 2012 5:09 pm
Subject: Re: [mongodb-user] Combining documents from two separate collections. Duplicate ids issue.

Best is to handle via application side logic instead of below commands.


 
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.
Raxit Sheth  
View profile  
 More options May 12 2012, 5:14 pm
From: Raxit Sheth <raxitsheth2...@gmail.com>
Date: Sun, 13 May 2012 02:44:43 +0530
Local: Sat, May 12 2012 5:14 pm
Subject: Re: [mongodb-user] Combining documents from two separate collections. Duplicate ids issue.

http://wrtsprt.wordpress.com/2011/08/17/merging-collections-in-mongodb/

you may want to chk comment also on this blog

On Sun, May 13, 2012 at 2:39 AM, Raxit Sheth <raxitsheth2...@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.
Adam C  
View profile  
 More options May 14 2012, 8:07 am
From: Adam C <ad...@10gen.com>
Date: Mon, 14 May 2012 05:07:12 -0700 (PDT)
Local: Mon, May 14 2012 8:07 am
Subject: Re: [mongodb-user] Combining documents from two separate collections. Duplicate ids issue.

If you are planning on having the field that may have duplicates be unique
(have a unique index), then you need to decide how you want to handle that
case.  The most obvious way is not to have a unique index on that field,
reconcile the differences etc. but it is really up to you.  See this for
example:

http://www.mongodb.org/display/DOCS/Indexes#Indexes-dropDups%3Atrue

Alternatively you may want to have more control over what happens, in which
case you might want to explore writing something yourself and using
application code to reconcile your data before insertion (if you do look at
the suggested merging collections link, be sure to take a look at
Kristina's comment about batch insert).

Adam

On Saturday, May 12, 2012 10:14:43 PM UTC+1, Raxit Sheth <Mobile 4 Mumbai>
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.
jeannot  
View profile  
 More options May 23 2012, 4:23 am
From: jeannot <jean.oll...@gmail.com>
Date: Wed, 23 May 2012 01:23:18 -0700 (PDT)
Local: Wed, May 23 2012 4:23 am
Subject: Re: Combining documents from two separate collections. Duplicate ids issue.
Hi,
I have the same problem. In my case, i'd if a document has an _id
already present in the collection, i'd like it to be regenerated to
make sure all documents are inserted. Is there an option for that? if
not, how can I remove the _id fields of dumped documents?
thanks
jean

On 14 mai, 14:07, Adam C <ad...@10gen.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.
Adam C  
View profile  
 More options May 23 2012, 5:46 am
From: Adam C <ad...@10gen.com>
Date: Wed, 23 May 2012 02:46:48 -0700 (PDT)
Local: Wed, May 23 2012 5:46 am
Subject: Re: Combining documents from two separate collections. Duplicate ids issue.

There is no automatic way to do this.  There are several of approaches you
could take though, for example:

You could restore the data to a new collection, identify the dupes, and
insert them without the _id field specified, that would mean a new _id
would be generated automatically.  Then you can simply drop the dupes when
you do your normal restore as I mentioned.

Or, you could write a script to iterate through the records check for
duplicates against your target collection, if found, generate a new one,
insert, otherwise insert as-is

Or, you could remove the unique index on the collection, restore all the
data, update the dupes in place and re-create the index

It's all about finding the right approach to fit your needs.

Adam


 
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.
jeannot  
View profile   Translate to Translated (View Original)
 More options May 30 2012, 7:39 am
From: jeannot <jean.oll...@gmail.com>
Date: Wed, 30 May 2012 04:39:54 -0700 (PDT)
Local: Wed, May 30 2012 7:39 am
Subject: Re: Combining documents from two separate collections. Duplicate ids issue.
Hi Adam,
Thanks for your answer, the first solution is ok for my problem
jeannot

On 23 mai, 11:46, Adam C <ad...@10gen.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.
Scott Hernandez  
View profile   Translate to Translated (View Original)
 More options May 30 2012, 7:46 am
From: Scott Hernandez <scotthernan...@gmail.com>
Date: Wed, 30 May 2012 07:46:52 -0400
Local: Wed, May 30 2012 7:46 am
Subject: Re: [mongodb-user] Re: Combining documents from two separate collections. Duplicate ids issue.
If you simply insert and there is existing document then you will get
an error and you can re-insert with a new _id value, or none, for that
document. To do this, and get back the error, you must do safe inserts
and handle the error case.


 
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 »