mongodb - $Where gives error -
i have collection containing data:
{ "_id" : objectid("51dfb7abe4b02f15ee93a7c7"), "date_created" : "2013-7-12 13:25:5", "referrer_id" : 13, "role_name" : "physician", "status_id" : "1", }
i sending query:
cmd { "mapreduce" : "doctor" , "map" : "function map(){emit(this._id,this);}" , "reduce" : "function reduce(key,values){return values;}" , "verbose" : true , "out" : { "merge" : "map_reduce"} , "query" : { "$where" : "this.demographics.first_name=='makdoctest'"} }
i getting error as:
"errmsg" : "exception: count failed in dbdirectclient: 10071 error on invocation of $where function:\njs error: typeerror: this.demographics has no properties nofile_a:0"
as sammaye says in comment:
it means somewhere in 1 of documents demographics null or not exist, need null check first, more importantly why dong in
$where
?
i go further that, , wouldn't use map/reduce mechanism here. slow, can't use indexes , can not run in parallel others.
you much better off using aggregation framework can like:
db.doctor.aggregate( [ { $match: { "demographics.first_name" : 'makdoctest' } }, { $group: …
you didn't specify final goal here, once can update answer.
Comments
Post a Comment