Unresolved error in Java Script stored in db.system.js.save on mongoDB. Please help

38 views
Skip to first unread message

y oswald

unread,
Mar 27, 2015, 3:26:33 PM3/27/15
to mongod...@googlegroups.com
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;
}
});

Will Berkeley

unread,
Mar 27, 2015, 3:30:31 PM3/27/15
to mongod...@googlegroups.com
Don't use server-side javascript. You can do the manipulation of the query string in client code.

What are you trying to accomplish with this code, exactly?

-Will

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/003e3e76-150c-4afd-8eea-09700f4a813c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

y oswald

unread,
Mar 27, 2015, 4:01:57 PM3/27/15
to mongod...@googlegroups.com
Hi  Will,
I will like to pass a series of conjunctive queries to this function such that it removes the 'and' in the query and searches for the remaining literals in the database.
If is on the client side, then i will need to type this function whenever i want to pass these conjunctive queries to the function, so that's why i want to save it on the server.

Will Berkeley

unread,
Mar 27, 2015, 4:03:53 PM3/27/15
to mongod...@googlegroups.com
I can see that that's what the code is doing - but what's the use case? Where are the conjunctions coming from? How will you use the results?

I don't understand quite what you mean when you say you'll have to type the function each time - what's your client environment? Just the mongo shell?

-Will

oswald

unread,
Mar 27, 2015, 5:02:46 PM3/27/15
to mongod...@googlegroups.com
I am just using the mongo shell. I am practicing mogodb, by trying to implement an algorithm/operator(dropping condition). conjunctions will be imputed by the user by invoking the 'dc' js function stored on the server-side. there's no real result use case as of now, am just experimenting..

-Oswald
Reply all
Reply to author
Forward
0 new messages