通过pythoneve和mong中的id数组找到多对多关系的干净方法

2024-10-03 17:21:19 发布

您现在位置:Python中文网/ 问答频道 /正文

在pythoneve中我有两个模型,分别是foo和bar,在foo中,我有一个objectid数组来引用bar。在pythoneve中,有没有一种干净的方法可以在flash中定义自定义路由并用mongo手动运行查询?在

如果我强迫在mongo中进行,那么推荐使用什么方式与mongo实例通信


Tags: 实例方法模型路由定义foomongo方式
1条回答
网友
1楼 · 发布于 2024-10-03 17:21:19

我不确定我是否理解您的问题,但是,您是否研究过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)或{}。另请参见this answer。在

希望这有帮助。在

相关问题 更多 >