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});
Run Code Online (Sandbox Code Playgroud)
通过输入以下2个shell命令对数据库dbTest运行:
> use dbTest
switched to dbTest
> load("test.js")
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.
但是,如果我尝试在脚本中包含"use"语句,它将失败:
//script filename: test.js (including "use" statement)
use dbTest;
db.cTest.save({Name: "Fred", Age:21});
Run Code Online (Sandbox Code Playgroud)
失败,错误消息如下:
> load("test.js")
SyntaxError: missing ; before statement
Mon Dec 19 11:56:31: Error: error loading js file temp.js (shell):1
Run Code Online (Sandbox Code Playgroud)
添加或删除分号到test.js似乎并不重要.
那么如何将"use"指令放入mongo shell脚本中呢?
我正在进行相对干净的OS X安装.我有Xcode,但删除了它.
当我输入时rvm install 1.9.3
,我得到:
max-macbook:~ max$ rvm install 1.9.3 Fetching yaml-0.1.4.tar.gz to /Users/max/.rvm/archives % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:--
--:--:-- 0 curl: (60) SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed More details here: http://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle" of Certificate Authority …
Run Code Online (Sandbox Code Playgroud) 是否可以选择MongoDB在mongorc.js中启动时应使用的数据库?
use dbname
Run Code Online (Sandbox Code Playgroud)
没有运作.这是一个非JavaScript宏.
我有一个var的特征
trait Foo {
@Id var _id: String
}
Run Code Online (Sandbox Code Playgroud)
现在我想初始化var
class Bar(s: String) extends Foo {
_id = s
}
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
error: class Bar needs to be abstract, since variable _id in class Foo of type String
is not defined (Note that variables need to be initialized to be defined) class Bar(s: String) extends Foo {
Run Code Online (Sandbox Code Playgroud)
关键是当使用特征时,注释是继承的,我想使用它.我想有一些带有一些注释的特性用于映射,并让它们在子类中可用.
有人可以提供想法,提示,解决方案吗?
编辑:
我忘了写下extends Foo
评论中提到的示例中的内容.所以这个例子是不完整的.
编辑:
当我var
在Trait中定义时,@Id var _id: String = _
我可以Bar
简单地写入_id = s
并且正确地继承了注释.但现在不必 …
mongodb ×2
annotations ×1
mongo-shell ×1
nosql ×1
ruby ×1
rvm ×1
scala ×1
scripting ×1
shell ×1
traits ×1