简体   繁体   English

如何使用MongoKit通过DBRef过滤字段?

[英]How to filter fields through DBRef using MongoKit?

I want to filter fields to a document containing DBRef when it's fetched. 我想在获取数据时将字段过滤到包含DBRef的文档。 The target filtering fields is a child document had relation using DBRef. 目标过滤字段是使用DBRef的子文档关系。 I wanna code like this. 我想这样编码。

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

The 'profile' field is using DBRef for this example. 对于此示例,“profile”字段使用DBRef。

Does someone have any idea? 有人有什么想法吗?

So User documents each have a DBRef to a Profile document? 那么每个用户文档都有一个DBRef到Profile文档? Looking at the MongoKit source, it seems to me that what you want isn't possible: 看看MongoKit源代码,在我看来,你想要的东西是不可能的:

https://github.com/namlook/mongokit/blob/master/mongokit/document.py#L647 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? 看看它如何做一个()(实际上是一个find())从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. 这就是MongoKit必须在一个字段列表中传递以包含或排除在引用的文档中,但MongoKit却没有。 You might open a feature request with the author, or see if you can add it yourself and submit a patch. 您可以向作者打开功能请求,或者查看是否可以自行添加并提交补丁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM