2013-07-28 57 views
4

基本上問題很簡單:MongoDB的查詢集合開始_

我怎樣才能在一個集合,這與開始發出查詢_?

例如,如果我有2個集合test_test,而我在mongoshell試圖db.test.findOne()db._test.findOne()第一個是如預期運行,而第二告訴我TypeError: db._testhas no properties (shell):1

回答

4

把它放在引號和使用getCollection方法。看到此article

實施例要創建集合_foo並插入{A:1}文件,使用下列操作:

db.getCollection("_foo").insert({ a : 1 }) 

要執行查詢,使用find()方法,在作爲如下:

db.getCollection("_foo").find()