2012-03-23 39 views
0

将db设置为某个任意值后,我无法在shell中执行任何操作。为什么变量'db'不是只读的?

它知道错误或预期的行为吗?

> use tutorial 
switched to db tutorial 
> db 
tutorial 

> db = 5 
5 
> db 
5 

> show dbs 
Fri Mar 23 17:18:40 TypeError: db.getMongo is not a function shell/utils.js:1235 
> 
> use tutorial 
Fri Mar 23 17:18:55 TypeError: db.getMongo is not a function shell/utils.js:1167 
> db = 'tutorial' 
tutorial 
> show dbs 
Fri Mar 23 17:19:38 TypeError: db.getMongo is not a function shell/utils.js:1235 
+2

患者:“当我这样做时会感到疼痛”。医生:“所以不要这样做” – 2012-03-23 18:35:53

回答

5

Mongo Interactive Shell是一个Javascript Shell,因此它遵从一个Javascript Shell的所有法则。您正在重写在启动过程中初始化的数据库变量。

> a = db 
SocialStreams 
> db = "Hello" 
Hello 
> db.help() 
Fri Mar 23 12:08:13 TypeError: db.help is not a function (shell):1 
> db = a 
SocialStreams 
> db.help() 
DB methods: 
    db.addUser(username, password[, readOnly=false]) 
    db.auth(username, password) 
    db.cloneDatabase(fromhost) 
...