Please I am new to mongoDB and I want to perform a search with js stored in mongoDB. Below is the js code stored in mongoDB.
When I perform the following query:
db.eval("dc(cough and asthma and cold)");
I get the following error message:
{
"errmsg" : "exception: SyntaxError: Unexpected identifier",
"code" : 16722,
"ok" : 0
}
Please can someone fix the above error for me ? Thanks in advance.
// save script to mongoDB
db.system.js.save({
_id : "countAnd" ,
value : function(userQuery){
return userQuery.toLowerCase().split("and").length;
}
});
//save dc 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;
}
});
You should take your string in quotes. Like this
db.eval("dc('cough and asthma and cold')");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.