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

Find by ObjectId #41

Closed
rewiaca opened this issue Jun 11, 2021 · 2 comments · Fixed by #43
Closed

Find by ObjectId #41

rewiaca opened this issue Jun 11, 2021 · 2 comments · Fixed by #43
Labels
bug Something isn't working

Comments

@rewiaca
Copy link

rewiaca commented Jun 11, 2021

Could not find by ObjectId. Code:

from bson.objectid import ObjectId

x = collection.find()
i = list(x)[0]['_id']

y = collection.find({'_id': ObjectId(i)})
print(list(y))

I see that database in mdb format has "_id": {"$oid": "id"} and I tried to find id in string with: {"_id.$oid": "string id"} but anyway, it would not work. Any suggestions? Thanks!

@davidlatwe
Copy link
Owner

Hi @rewiaca ,

I see that database in mdb format has "_id": {"$oid": "id"} ..

That should be JSON serialized format which used for saving document in disk, not how the document looks in database.

Back to the main issue.

I think this is a bug. If you change to import ObjectId class from montydb.types.bson_, you should find the doc.

from montydb import MontyClient
from montydb.types.bson_ import ObjectId

client = MontyClient(":memory:")
collection = client["test"]["col"]

x = collection.find()
i = list(x)[0]['_id']

y = collection.find({'_id': ObjectId(i)})
print(list(y))

@davidlatwe davidlatwe added the bug Something isn't working label Jun 11, 2021
@rewiaca
Copy link
Author

rewiaca commented Jun 11, 2021

@davidlatwe, thanks!
from montydb.types.objectid import ObjectId
Worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants