Skip to content

Not founding key in document even though key exists #116

@azeredo-e

Description

@azeredo-e

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions