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

orderBy silently creating a collection with unique keys #1957

Open
1toddlewis opened this issue Apr 12, 2024 · 2 comments
Open

orderBy silently creating a collection with unique keys #1957

1toddlewis opened this issue Apr 12, 2024 · 2 comments

Comments

@1toddlewis
Copy link

1toddlewis commented Apr 12, 2024

I have a table full of board games owned by my friends and details about them. The primary key for the table is a collection ID that is unique to each copy. There is also an objectId that correlates to the game, that is indexed.

Some versions of the same game have different names. For example, Carabande (a game where you flick disks around a racetrack) is also called PitchCar, but they share the same objectId -- they are two different names for the same game.

When I order the table by objectId, orderBy is quietly creating a collection that only has one document per objectId. A subsequent filter looks for a portion of a game title, and PitchCar is completely missing. It's not even in the collection to be found. orderBy selected the document for Carabande to represent that objectId.

I can order by the primary key as a workaround, but then I lose the ability to use eachUniqueKey later. I could write my own collection.each function that removes duplicates, but it feels like orderBy is doing more work than it should be.

@dfahlander
Copy link
Collaborator

orderBy is basically iterating the index. But it sounds like the unique flag is set on the collection when you do the ordering. Try whether the call to eachUniqueKey() could be done on another collection instance to not affect the one you do orderBy on. I think the problem city could be the collection instance being reused

@1toddlewis
Copy link
Author

Interesting. Okay, I'll give it a try. I quickly implemented the workaround mentioned above, removing orderBy and writing my own de-duping function for collection.each(). But I'll check out using a different collection instance.

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

2 participants