Skip to content
This repository has been archived by the owner on Apr 27, 2018. It is now read-only.

unexpected token error with insertMany #18

Closed
chrisdias opened this issue May 9, 2017 · 1 comment
Closed

unexpected token error with insertMany #18

chrisdias opened this issue May 9, 2017 · 1 comment
Assignees

Comments

@chrisdias
Copy link
Member

chrisdias commented May 9, 2017

this fails with "unexpected token i in JSON at position 2". Note the space between { and id:

db.stickers.insertMany([
    { id: '1',
        tags: [ 'Deployment' ],
        name: 'Docker',
        description: 'The Docker container-based platform deployment system',
        author: 'Docker',
        size: {
            width: '2in',
            height: '2in'
        },
        image: '/img/logo/docker.png'
    }, {
        id: '2',
        tags: [ 'Service' ],
        name: 'Trello',
        description: 'The Trello project management service',
        author: 'Trello',
        size: {
            width: '2in',
            height: '2in'
        },
        image: '/img/logo/trello.png'
    }
])

This works (note no space between the first { and id):

db.stickers.insertMany([
    {id: '1',
        tags: [ 'Deployment' ],
        name: 'Docker',
        description: 'The Docker container-based platform deployment system',
        author: 'Docker',
        size: {
            width: '2in',
            height: '2in'
        },
        image: '/img/logo/docker.png'
    }, {
        id: '2',
        tags: [ 'Service' ],
        name: 'Trello',
        description: 'The Trello project management service',
        author: 'Trello',
        size: {
            width: '2in',
            height: '2in'
        },
        image: '/img/logo/trello.png'
    }
])
@sandy081
Copy link
Member

sandy081 commented May 9, 2017

@chrisdias Good catch. This is not because of the space. My Grammar is currently handling only JSON objects/arrays. And above is a JavaScript object. Hence my JSON parsing is failing. I have two code paths to execute scripts internally, one using the node library (which needed JSON parsing) and the other pipe the text to mongo shell. I would like to move away from mongo shell to node library. Currently following commands are executed using node lib

  • find commands
  • insert commands

Due to invalid grammar, there are randomly generated nodes which caused both to take different paths. Hence first (taking the node library) is failing and the other (taking shell path) is working.

Fixed it

  • Enhanced grammar to support Javascript objects

Now, insert with JSON or JavaScript object is supported and both go through node API path.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants