1

I am firing mgo from GoLang on MongoDb to find records which have trimmed string length greater than zero, I tried below but neither is working, please help.

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": ".*.*"}
planet_hunter
  • 3,866
  • 1
  • 26
  • 39
Nikhil Joshi
  • 817
  • 2
  • 12
  • 34

2 Answers2

2

If you are looking just for non-empty values, try this:

bson.M{"$exists": true, "$ne": ""}
Kevin Sandow
  • 4,003
  • 1
  • 20
  • 33
0

Another way or another approach would be to check if 0th element of array exists or not.

"arr.0" : bson.M{"$exists": true}
Saransh
  • 629
  • 2
  • 8
  • 14