代码之家  ›  专栏  ›  技术社区  ›  Stephen

MongoDB如何使用$not、$和/$或$type?

  •  0
  • Stephen  · 技术社区  · 10 年前

    对于相同的字段名,我有不同的数据类型 f

    具有 this 参考

    我想找到所有不是 Double 而不是 NULL

    我能找到那些不是 双重的 通过

    db.foo.find({ f:{$not:{$type:1}} })
    

    但不能将查询与not组合 无效的

    尝试使用

    db.foo.find({f:{$not:{$and:[{$type:1},{$type:10}]}}})'
    db.foo.find({$and:[{f:{$not:{$type:1}}}, {f:{$not:{$type:10}}}] })
    

    但那失败了

    有什么帮助吗?

    1 回复  |  直到 10 年前
        1
  •  2
  •   Neil Lunn    10 年前

    你想要的是 $nor 条件

    db.foo.find({ $nor:[ { f: {$type:1} }, { f: null }] })
    

    这意味着 没有一个 包含的参数中的是true。也不是查找 null 价值