linux - 多行复制粘贴到 mongo shell

标签 linux bash mongodb terminal

我如何简单地将多行复制粘贴到 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

> ])

最佳答案

在您的原始查询中修复此行:

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

以下内容:

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

然后复制粘贴就可以了。问题是引号。

关于linux - 多行复制粘贴到 mongo shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37817961/

相关文章:

linux - 如何删除多个相同扩展名的文件但保留最新的

linux - Bash 中的简单日志记录级别

linux - 虚拟机能否像基于硬件的操作系统一样高效?

node.js - 由于缺少 MongoDB,无法在全新安装的 Ubuntu Linux 上运行 Meteor 应用程序

python - 访问具有可变长度的元组列表的元素并以相同的格式保存输出

java - 连续运行shell脚本时JVM进入休眠状态

spring - 在 Spring 解决 mongodb 引用

node.js - 如果不存在如何创建项目并在存在时返回错误

c# - 如何正确模拟 MongoDb 客户端

linux - 如何在 Linux 流量控制 (tc) 中通过 ematch 排除端口范围?