Mongodb 怎样对 key 进行模糊查询?

2021-12-30 19:09:40 +08:00
 ptrees

直接上例子: { "groups": { "a": [ { "id": 1, "status": "open" }, { "id": 2, "status": "open" }, { "id": 3, "status": "closed" } ], "b": [ { "id": 4, "status": "closed" }, { "id": 5, "status": "open" }, { "id": 6, "status": "closed" } ] } }

对这个数据,怎么实现类似 find({"groups.*.status": "closed"}) 这样的查询?

2117 次点击
所在节点    MongoDB
3 条回复
defunct9
2021-12-30 19:13:48 +08:00
.filter
shadow1949
2021-12-31 10:11:03 +08:00
unwind
galikeoy
2021-12-31 11:15:34 +08:00
objectToArray
unwind
unwind
性能不好,建议拿数据到代码里操作

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/825366

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX