[SERVER-35481] _id field in unique index will return all results with a distinct ObjectId Created: 07/Jun/18 Updated: 27/Oct/23 Resolved: 11/Jun/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Index Maintenance |
| Affects Version/s: | 3.2.11 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Romain CAMPIGOTTO | Assignee: | Nick Brewer |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL |
| Participants: |
| Description |
|
I design an academic distributed application in which I have a program who streams and collects tweets (via Twitter Streaming API), in particular profiles (authors informations) on a dedicated collection in my MongoDB database. In this collection, I have a unique index applied on 2 fields. My distributed application works with Apache Camel framework and with RabbitMQ server. When I set a number of consumers > 1 behind my streamer, I get duplicates in my collection. More precisely, for each duplicate entry, I have an incomplete entry (with numerous missing fields) and a complete entry. If I drop and try to re-create unique index, I get an error, saying duplicates are present in collection. I think it is a concurrent access problem, since collected date of each duplicate entries are very close. I give below an example of duplicates, with current applied indexes on the collection:
|
| Comments |
| Comment by Nick Brewer [ 11/Jun/18 ] |
|
Hi Romain, The 1 and -1 values are used to specify whether an ascending or descending index sort is used, per the Compound index documentation. While this is more thoroughly documented in relation to compound indexes, it is true of single-key indexes as well. If you want to create a unique index against, for example, the "broadcaster" and "account_id" fields, I'd suggest removing the " _id" field from your unique indexes. Regards, Nick |
| Comment by Romain CAMPIGOTTO [ 08/Jun/18 ] |
|
Thank you Ramon Fernandez for your quick answer. No, I have not doc where all three keys are the same. |
| Comment by Ramon Fernandez Marina [ 07/Jun/18 ] |
|
zankosax, the two documents that you reference have a distinct _id field, so therefore both are allowed in the unique index. Do you have some other docs where all three keys are the same? Thanks, |