Reputation: 633
I have a collection containing data:
{
"_id" : ObjectId("51dfb7abe4b02f15ee93a7c7"),
"date_created" : "2013-7-12 13:25:5",
"referrer_id" : 13,
"role_name" : "Physician",
"status_id" : "1",
}
I am sending the 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 am 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"
Upvotes: 0
Views: 235
Reputation: 36784
As Sammaye says in a comment:
It means that somewhere in one of your documents demographics is null or does not exist, you need to do a null check first, but more importantly why are you dong this in a
$where
?
I would go even further that that, and I wouldn't even use the Map/Reduce mechanism here. It slow, can't use indexes and can not run in parallel with others.
You would be much better off using the Aggregation Framework where you can do something like:
db.doctor.aggregate( [
{ $match: { "demographics.first_name" : 'makdoctest' } },
{ $group: …
You didn't specify the final goal here, but once you do I can update the answer.
Upvotes: 1