I have already seen these posts:
String field value length in mongoDB
Select string length in mongodb
But My problem is different. When I am running this query:
db.usercollection.find({$where: "this.profile.name.length < 20"}).limit(2);
I am getting the below error:
Error: error: {
"ok" : 0,
"errmsg" : "TypeError: this.profile is undefined :\n_funcs2@:1:24\n",
"code" : 139
}
when I am running this query:
db.usercollection.find({"profile.name": {$exists: true}, $where: "this.profile.name.length <20"}).limit(2);
No error, But empty result, though my collection have 2 documents where profile.name<20
MongoDB shell version: 3.2.11