推荐工具
RoboMongo
推荐书目
50 Tips and Tricks for MongoDB Developers
Related Blogs
Snail in a Turtleneck
ptrees
V2EX  ›  MongoDB

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

  •  
  •   ptrees · Dec 30, 2021 · 3144 views
    This topic created in 1592 days ago, the information mentioned may be changed or developed.

    直接上例子: { "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"}) 这样的查询?

    3 replies    2021-12-31 11:15:34 +08:00
    defunct9
        1
    defunct9  
       Dec 30, 2021
    .filter
    shadow1949
        2
    shadow1949  
       Dec 31, 2021
    unwind
    dfourc
        3
    dfourc  
       Dec 31, 2021
    objectToArray
    unwind
    unwind
    性能不好,建议拿数据到代码里操作
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3226 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 14:19 · PVG 22:19 · LAX 07:19 · JFK 10:19
    ♥ Do have faith in what you're doing.