Insert document with date into collection in Robomongo

20,629

Solution 1

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

Solution 2

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.

Share:
20,629
Lars Holdgaard
Author by

Lars Holdgaard

An entrepreneur since I was 18. Been building a lot of stuff: some successful, some not so successful Currently building the best debt collection company in the world at Likvido. In my free time (when not tinkering with code), I'm very much into crypto, traveling and being digital-nomad when it suits my lifestyle... And I blog at LarsHoldgaard.com!

Updated on July 05, 2022

Comments

  • Lars Holdgaard
    Lars Holdgaard almost 2 years

    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?

  • Stennie
    Stennie almost 10 years
    Actually, Date.now() works fine. The issue with dates that you referenced is in regards to constructing a new Date() using an ISO string, which you can use ISODate(...) for.