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

Not founding key in document even though key exists #116

Open
azeredo-e opened this issue Dec 6, 2023 · 0 comments
Open

Not founding key in document even though key exists #116

azeredo-e opened this issue Dec 6, 2023 · 0 comments

Comments

@azeredo-e
Copy link

azeredo-e commented Dec 6, 2023

I have a collection and in each document there are a certain set of fields, but not all documents contain all fields. For example, in collection "foo" we can have three documents:

{"client_name": "john doe",
 "product": "car",
 "car_colour": "red"},
{"client_name": "jane doe",
 "product": "bike",
 "bike_colour": "blue"},
{"client_name": "jack doe"
 "product": NULL}

Each one is a client that bought a certain product and because of that other fields reflect the product that he bought and not every document has every single field.

If I was trying to retrieve all documents i would use:

filter = Mongoc.BSON("""{"projection": {"car_colour": true}}""")
res = Mongoc.find(foo, options=filter)

It would return an error stating: KeyError: key "car_colour" not found

I was expecting to it return all documents and in those docs that have fields that don't exists in other documents, just return empty in that field. From my experience Python does something similar with PyMongo.

Julia: 1.9.1 Mongoc: 0.9.0

edit: Added version of Julia and Mongoc

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