2012-03-23 24 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) 
...