简体   繁体   English

Mongo查询以查找属性不是空字符串的所有记录

[英]Mongo query to find all records where attribute is not an empty string

Trying to find all records where attribute is not an empty string. 尝试查找属性不是空字符串的所有记录。

db.player.find({name: {$not: ''}})

gives the error: 给出错误:

error: {
    "$err" : "Can't canonicalize query: BadValue $not needs a regex or a document",
    "code" : 17287
}

Do i have to use a regex to do this or is there a simpler way to check for empty strings using mongo? 我必须使用正则表达式来执行此操作还是使用mongo检查空字符串的更简单方法?

为此使用$ne

db.player.find({name: {$ne: ''}})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM