-
Notifications
You must be signed in to change notification settings - Fork 83
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
Prevent sorting by identical dates from duplicating documents #23
Conversation
Thank you for identifying and submitting a fix for this bug. I do believe however that it may be a good idea to fix the underlying root cause which would also address undiscovered bugs affected by We could introduce a more appropriate |
Hi @kofrasa. Looking into your suggestion, its not possible to pass a custom comparator function to Would be interested to hear your thoughts on the above! Thanks |
Hi @microadam My tests given below show that both Given that For user-defined types as sort keys, that will mean sorting them in natural order post object "stringification". Would like your feedback. Testing _.uniq and uniq (I used "Try it out" links on npm page)function Person(name, age) {
this.name = name;
this.age = age;
}
var a = new Person("john", 12);
var b = new Person("john", 12);
var c = {name: "john", age: 12};
var d = {name: "john", age: 12};
// we expect 1 in both cases
console.log(uniq([a,b]).length); // 2
console.log(uniq([c,d]).length); // 2 |
I noticed that switching to using the internal |
Hi @kofrasa, sounds great to me! I was just about to pick this up again. Thanks for coming up with a better fix, I look forward to seeing it! |
@kofrasa I have update this PR, this seems to fix my issue, is this the sort of thing you were thinking of? |
Yes something similar to what you have. I added a unit test based on your example and took the opportunity to also change the implementation of Thanks for the update. |
Looks like it works to me! Thank you very much :) will close this PR! |
With documents like:
and a find like:
.find({}, { sort: { date: 1 } })
Documents are returned like:
This fixes the problem.
The issue is due to
_.uniq
not being able to unique date objects. This converts the date objects to strings so they can be uniqued and then sorted appropriately.