V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐工具
RoboMongo
推荐书目
50 Tips and Tricks for MongoDB Developers
Related Blogs
Snail in a Turtleneck
ptrees
V2EX  ›  MongoDB

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

  •  
  •   ptrees · Dec 30, 2021 · 3148 views
    This topic created in 1593 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   ·   3258 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 13:58 · PVG 21:58 · LAX 06:58 · JFK 09:58
    ♥ Do have faith in what you're doing.