gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 04:43:18 26 4
gpt4 key购买 nike

我在 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。另请参阅this answer .

希望这有帮助。

关于python - 在 python-eve 和 mongo 中通过 id 数组查找多对多关系的干净方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30066671/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com