Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline copy-paste to mongo shell

How do I simply copy-paste multiple lines into the mongo shell. Is the only way to use a script file? I want to quickly insert a bunch of data, but the below happens:

> db.mycollection.insert([
...    {
...       title: 'MongoDB Overview', 
...       description: 'MongoDB is no sql database',
...       by: 'tutorials point',
...       url: 'http://www.tutorialspoint.com',
...       tags: ['mongodb', 'database', 'NoSQL'],
...       likes: 100
...    },
... 
...    {
...       title: 'NoSQL Database', 
...       description: 'NoSQL database doesn't have tables',
2016-06-14T17:40:30.303+0100 E QUERY    [thread1] SyntaxError: missing } after property list @(shell):13:41

>       by: 'tutorials point',
...       url: 'http://www.tutorialspoint.com',
...       tags: ['mongodb', 'database', 'NoSQL'],
...       likes: 20, 
...       comments: [
...          {
...             user:'user1',
...             message: 'My first comment',
...             dateCreated: new Date(2013,11,10,2,35),

...             like: 0 
...          }
...       ]
2016-06-14T17:40:30.335+0100 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):2:9

>    }
2016-06-14T17:40:30.344+0100 E QUERY    [thread1] SyntaxError: expected expression, got '}' @(shell):1:0

> ])
like image 635
darkace Avatar asked Oct 31 '22 01:10

darkace


1 Answers

Fix this line in your original query:

description: 'NoSQL database doesn't have tables',

To the following:

description: "NoSQL database doesn't have tables",

Then copy and pasting will work. The issue is the quotation marks.

like image 125
Kairat Avatar answered Nov 02 '22 09:11

Kairat