Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent results returned with unique index #2042

Closed
cyberwombat opened this issue Apr 25, 2014 · 2 comments
Closed

Inconsistent results returned with unique index #2042

cyberwombat opened this issue Apr 25, 2014 · 2 comments

Comments

@cyberwombat
Copy link

Basically if I have a field with unique:true then trying to fetch all results returns a random amount of items. I have 4013 items in the db. Here's the schema.

var Order = new Schema({
 code: {
  type: String,
  unique: true
},
...
});

Now run some queries:

Order.find().exec(function(err, orders) {
 console.log(orders.length); // always 101 
})

Order.find().limit(100000).exec(function(err, orders) {
 console.log(orders.length); // varies, sometimes 1150, 1790, 2046 - never more
})

Now if I remove the 'unique: true' from schema it will always return the total amount:

Order.find().exec(function(err, orders) {
 console.log(orders.length); // always 4013 (correct total)
})

Any idea as to why this behavior occurs? afaik the codes are all unique (orders from a merchant). This is tested on 3.8.6, 3.8.8

@cyberwombat
Copy link
Author

Here's my guess - there are duplicate items in there and Mongo is freaking out and choking in a sync way - it never gets higher than 2046 whichI bet is a duplicate - a few times it will stop early so I think it a) stops on duplicate and b) it does so sync or not in same "process" as fetching and will sometimes stop earlier. I bet if I remove the dups it will prob work though I wish there was some errors. Does that sound about right?

@cyberwombat
Copy link
Author

I am guessing it's related to this #1225

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant