baichi
V2EX  ›  问与答

各位大佬,我想在 mongoDB 里找在 A=1 的数据中 排除 (B=2 同时 C=3) 的数据, 查询语句应该怎么写呢?

  •  
  •   baichi · Aug 24, 2017 · 2090 views
    This topic created in 3271 days ago, the information mentioned may be changed or developed.
    先谢过各位
    4 replies    2017-08-25 20:21:19 +08:00
    corningsun
        1
    corningsun  
       Aug 25, 2017   ❤️ 1
    db.col.find({A:1, $or: [B:{$ne:2}, C:{$ne:3}]})

    where A=1 and (B!=2 or C!=3)
    corningsun
        2
    corningsun  
       Aug 25, 2017
    我照着例子拼出来的,没试过。。。
    http://www.runoob.com/mongodb/mongodb-query.html
    baichi
        3
    baichi  
    OP
       Aug 25, 2017
    @corningsun 这样写, 只是排除了 B 不等于 2 或 C 不等于 3 二选一的项, 而我想要的是, 排除 B 等于 2 同时 C 等于 3 的项, 不过还是谢谢
    baichi
        4
    baichi  
    OP
       Aug 25, 2017
    @corningsun 抱歉刚才脑抽了 你是对的 是我错了 再次感谢🙏
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2818 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 03:50 · PVG 11:50 · LAX 20:50 · JFK 23:50
    ♥ Do have faith in what you're doing.