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

Mongo: unable to sort by mutilple fields with correct field priority #2452

Open
p-mitana opened this issue Jun 19, 2020 · 0 comments
Open

Mongo: unable to sort by mutilple fields with correct field priority #2452

p-mitana opened this issue Jun 19, 2020 · 0 comments

Comments

@p-mitana
Copy link

Let's assume we have collection with the following data:

{text: "a", number: 1}
{text: "a", number: 2}
{text: "b", number: 1}
{text: "b", number: 2}

We want to find the data and sort them in two ways:

  1. by text and then by number -> (a, 1), (a, 2), (b, 1), (b, 2)
  2. by number and then by text -> (a, 1), (b, 1), (a, 2), (b, 2)

While this is possible in Mongo (.sort({ text: 1, number: 1 }) vs .sort({ number: 1, text: 1 })), it is not possible in vibe.d. The reason is that Mongo respects order of fields in an object passed to sort(), while D's associative arrays don't preserve key order.

As the one with design flaw is actually Mongo (as I guess that in BSON as in JSON key order should not be relevant for objects), probably a non-stantard API should be created to enable such sorts.

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