Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert document with date into collection in Robomongo

Tags:

mongodb

robo3t

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?

like image 425
Lars Holdgaard Avatar asked Jul 23 '14 10:07

Lars Holdgaard


2 Answers

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.

like image 196
Stennie Avatar answered Nov 16 '22 01:11

Stennie


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+).

like image 30
Lix Avatar answered Nov 16 '22 03:11

Lix