2016-06-14 342 views
2

如何簡單地將多行復制粘貼到mongo shell中。是使用腳本文件的唯一方法嗎?我想快速插入一組數據,但低於發生:將多行復制粘貼到mongo shell

> 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 

> ]) 

回答

2

修復此線在你的原始查詢:

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

以下幾點:

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

然後複製並粘貼將工作。問題是引號。