通过 python-eve 和 mongo 中的 id 数组查找多对多关系的简洁方法

Clean way to find many to many relations by array of ids in python-eve and mongo

我在 python 前夕有 2 个模型,分别是 foo 和 bar,在 foo 中我有一个引用 bar 的 objectId 数组。在 python-eve 中是否有一种干净的方法可以做到这一点,而无需在 flash 中定义自定义路由,并且 运行 使用 mongo 手动查询?

如果我在 mongo 中强制这样做,推荐的与 mongo 实例通信的方式是什么

我不确定我是否理解您的问题,但是,您是否查看了 data_relation 设置?参见 Embedded Resource Serialization。引用 限制 段落:

Currently we support embedding of documents by references located in any subdocuments (nested dicts and lists). For example, a query /invoices?/embedded={"user.friends":1} will return a document with user and all his friends embedded, but only if user is a subdocument and friends is a list of reference (it could be a list of dicts, nested dict, ect.). We do not support multiple layers embeddings. This feature is about serialization on GET requests. There’s no support for POST, PUT or PATCH of embedded documents.

已更新 如果您只是想查询在其他集合中引用文档的文档,那么这样的事情会起作用:

?where={"reference_field":"54e328ec537d3d20bbdf2ed5"}

假设 reference_field 是一个 ID 列表(objectid 类型)或一个 objectid。另见 .

希望对您有所帮助。