2013-07-28 60 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()