【发布时间】:2012-01-23 19:43:45
【问题描述】:
Windows XP 机器上的 32 位 mongo 2.0.1
//script filename: test.js (one line shell script file to store a person)
db.cTest.save({Name: "Fred", Age:21});
通过输入以下 2 个 shell 命令对数据库 dbTest 运行:
> use dbTest
switched to dbTest
> load("test.js")
到目前为止,一切都很好。
但如果我尝试在脚本中包含“use”语句,它会失败:
//script filename: test.js (including "use" statement)
use dbTest;
db.cTest.save({Name: "Fred", Age:21});
失败,错误信息如下:
> load("test.js")
SyntaxError: missing ; before statement
Mon Dec 19 11:56:31: Error: error loading js file temp.js (shell):1
在 test.js 中添加或删除分号似乎并不重要。
那么如何将“use”指令放入 mongo shell 脚本中呢?
【问题讨论】: