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

Index does not seem to maintain expected sort order #855

Open
jusexton opened this issue Aug 30, 2023 · 0 comments
Open

Index does not seem to maintain expected sort order #855

jusexton opened this issue Aug 30, 2023 · 0 comments

Comments

@jusexton
Copy link

Problem

I am creating a compound index and specifying that items should be sorted in descending order by age. Mongomock does not seem to honor the sort order of the index.

Reproduce

import mongomock
import pymongo

client = mongomock.MongoClient()
collection = client['test_db']['test_collection']
collection.create_index([('name', pymongo.ASCENDING), ('age', pymongo.DESCENDING)])

data = [
    {'name': 'Foo', 'age': 5},
    {'name': 'Foo', 'age': 10}
]
collection.insert_many(data)

for person in collection.find({'name': 'Foo'}):
    print(person)

The above prints:

{'name': 'Foo', 'age': 5, '_id': ObjectId('64ef880e30cb3b4053d1c7c8')}
{'name': 'Foo', 'age': 10, '_id': ObjectId('64ef880e30cb3b4053d1c7c9')}

I would expect:

{'name': 'Foo', 'age': 10, '_id': ObjectId('64ef880e30cb3b4053d1c7c9')}
{'name': 'Foo', 'age': 5, '_id': ObjectId('64ef880e30cb3b4053d1c7c8')}

Am I doing anything wrong or is this a bug?

Version Info

pymongo = 4.4.0
mongomock = 4.1.2

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