pythonmongodbpymongomongokit

How to filter fields through DBRef using MongoKit?


I want to filter fields to a document containing DBRef when it's fetched. The target filtering fields is a child document had relation using DBRef. I wanna code like this.

db.User.find(fields=['_id', 'profile._id', 'profile.text'])

The 'profile' field is using DBRef for this example.

Does someone have any idea?


Solution

  • So User documents each have a DBRef to a Profile document? Looking at the MongoKit source, it seems to me that what you want isn't possible:

    https://github.com/namlook/mongokit/blob/master/mongokit/document.py#L647

    See how it does one() (which is effectively a find()) to fetch the referred-to document from MongoDB? That's where MongoKit would have to pass in a list of fields to include or exclude in the referred-to doc, but MongoKit does not. You might open a feature request with the author, or see if you can add it yourself and submit a patch.