如何检查字符串长度是否为>;mongodb中的0?

如何检查字符串长度是否为>;mongodb中的0?,mongodb,Mongodb,我在MongoDb上从GoLang解雇mgo以查找字符串长度大于零的记录,我在下面进行了尝试,但都不起作用,请帮助 findQuery["shopname"] = bson.M{"$where": "len > 0"} findQuery["shopname"] = bson.M{"$where": "shopname.len > 0"} findQuery["shopname"] = bson.M{"$where": "this.shopname.len > 0"} find

我在MongoDb上从GoLang解雇mgo以查找字符串长度大于零的记录,我在下面进行了尝试,但都不起作用,请帮助

findQuery["shopname"] = bson.M{"$where": "len > 0"}
findQuery["shopname"] = bson.M{"$where": "shopname.len > 0"}
findQuery["shopname"] = bson.M{"$where": "this.shopname.len > 0"}
findQuery["shopname"] = bson.M{"$regex": ".*.*"}

如果只查找非空值,请尝试以下操作:

bson.M{"$exists": true, "$ne": ""}

另一种方法是检查数组的第0个元素是否存在

"arr.0" : bson.M{"$exists": true}

请帮助,无法找到解决方法。这与Go无关。非常感谢可能的副本,您是最好的!