I am new to MongoDB. I am just following tutorialspoint.com for learning mongoDB.
I executed these two commands exactly as given :
db.test.save( { a: 1 } )
db.test.find(){ "_id" : ObjectId(5879b0f65a56a454), "a" : 1 }
I am getting error SyntaxError: Unexpected Token {
Any help is appreciated. Thanks.
Your query:
test.find() { "_id" : ObjectId(5879b0f65a56a454), "a" : 1 }
Correct query:
test.find( { "_id" : ObjectId("5879b0f65a56a454"), "a" : 1 })
you need to include curly braces in the round brackets like ({}) second thing enclose id in quotes, please refer the mongodb manual
http://docs.mongodb.org/manual/reference/method/db.collection.find/
Something stupid I did that got me into this type of error, I would like to share here :
I was OUTSIDE of mongo shell and executing below command. I was using my smartphone and trying to update a record while I was travelling to my office via metro. I never felt for a minute that I was out of the shell unless I saw 'bash' and got to know how ignorant I was. By the way below is the query I was trying to execute with error :
karsh45:~/workspace $ db.users.updateOne({name:"dummyUser4"}, {$set:{email:"[email protected]"}}); bash: syntax error near unexpected token `{name:"dummyUser4"},'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With