Hello all, I am fairly new to the world of mongoDB and I need some help with performing a search using js stored in mongoDB. Below you will find the javascript code that is stored in my mongoDB database.
When attempting the query below:
db.eval("dc(cough and asthma and cold)");
I encountered the following error message:
{
"errmsg" : "exception: SyntaxError: Unexpected identifier",
"code" : 16722,
"ok" : 0
}
Could someone kindly assist me in resolving the above error? Your assistance is greatly appreciated.
// Saving script to mongoDB for future use
db.system.js.save({
_id : "countAnd" ,
value : function(userQuery){
return userQuery.toLowerCase().split("and").length;
}
});
//Saving 'dc' function to mongoDB
db.system.js.save({
_id : "dc",
value: function(userQuery){
var numOfAnds = countAnd(userQuery);
var uQuery = userQuery.toLowerCase().split("and",numOfAnds);
var dcResults ="";
for(var i=0; i<uQuery.length; i++){
var dcResults =db.records.find({diagnosis:uQuery[i]},{diagnosis:true});
}
return dcResults;
}
});