I am working with Robomongo, where I am manually inserting an object.
I want to have a field on my object, which is the current date. Normally I am used to use Date.now()
in Javascript. However, when I use the insert document form in the Robomongo tool, I get:
Unable to parse JSON:
Expecting '(', at (4, 15).
Sample JSON:
{
serial: '1231323123',
game: 'World of Warcraft',
date: Date.now()
}
Any idea how to insert this record?
Your example works fine if you insert it in the Robomongo 0.8.4 shell prompt directly, for example into a game
collection:
db.game.insert({
serial: '1231323123',
game: 'World of Warcraft',
date: Date.now()
})
If you use the context menu (Insert Document...
), the JSON parser will return the syntax error you are encountering.
The issue here is that the JSON validation is currently done with a library that is not specific to MongoDB. The above is not valid JSON for several reasons (unquoted keys, and the unquoted function value) but is valid to insert in the mongo
shell.
I've created Robomongo issue #619 for this. A related JSON validation difference is issue #448.
Until the JSON validation error is fixed, I would suggest inserting documents like this via the shell prompt in Robomongo instead.
Unfortunately, at this stage it is impossible to do this as stated in the following github issue:
https://github.com/paralect/robomongo/issues/477
...there are several differences between Robomongo's JavaScript engine and the v8 engine which is the default in mongo shell 2.4+.
Issue #520 should fix the problem by updating the built-in shell that comes with Robomongo from SpiderMonkey to v8 (default in MongoDB 2.4+).
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