Reputation:
I have a bash script , from which i run js file which is responsible to update the table with a new filed if it doesn't exists .
But while executing bash script , i am getting the following error .
Wed Jul 3 00:05:18 Error: error doing update (anon):1552
failed to load: logincount.js
This is a simple js file which will update a field called as yesterday inside userCollection table
var d = new Date();
var curr_date = d.getDate()-1;
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
var yesterday = curr_year + "-" + curr_month + "-" + curr_date;
db.userCollection.update({yesterday : {$exists : false}}, {$set: {yesterday : yesterday}},false,true)
Please let me know if there is any wrong the above js file and what is the reason for this error ??
please advice , thanks in advance
One more thing i have forgot to update if i remove the last line , the below line
db.userCollection.update({yesterday : {$exists : false}}, {$set: {yesterday : yesterday}},false,true)
it doesn't complain anything . i guess that if the filed yesterday should be global or what ?? if yes then how can i make that field global ??
Upvotes: 2
Views: 5493
Reputation: 30136
The variable db is not defined. Take a look here: http://docs.mongodb.org/manual/tutorial/write-scripts-for-the-mongo-shell/
You can do this:
conn = new Mongo();
db = conn.getDB("myDatabase");
or this:
db = connect("localhost:27020/myDatabase");
Upvotes: 1