2015-11-03 132 views
1

我需要在名稱爲「group」的集合中對mongodb執行find()命令,但「group」顯然是保留名稱,所以..我需要使用其他命令選擇它的行。在這種情況下我該如何做find()?Mongodb查找並保留名稱

我的測試:

> db['group'].find() 
Tue Nov 3 09:30:22.132 TypeError: Object function (parmsObj){ 
var ret = this.runCommand({ "group" : this._groupFixParms(parmsObj) }); 
    if (! ret.ok){ 
     throw "group command failed: " + tojson(ret); 
    } 
    return ret.retval; 
} has no method 'find' 

回答

2

使用

db.getCollection("group").find() 

在你的情況下,db.getCollection()方法是一個集合,其名稱可能與外殼本身,這樣的名字即開始互動相當有用與_或鏡像數據庫命令如groupcount

+0

它的工作原理,謝謝! – balancin

+1

@balancin無後顧之憂,高興地幫助:) – chridam