Since this is for a homework assignment I do not want to post my code because it essentially gives a solution. I can post some generic snippets. I am going to start off by saying I am new to javascript and Mongo, and basically learned them in a few hours last night.
Basically I have code that when I paste into the shell, it works perfectly, but when I save it into the database and try to execute it does not work. Here is a basic example.
db.system.js.save(
{
_id: "istrue",
value: function (x){
if(x == true)
print("true");
else
print("false");
}
})
So if I copy and paste this code and set var x = true
or var x = false
first then it works, but if I do this:
db.eval("istrue(true);");
Then it doesn't work.
Any ideas?