MongoDB创建集合失败。

3
我正在尝试:

1. 创建一个数据库
use testdb switched to db testdb

2. 创建集合

testdb.createCollection(testcollection)

我得到了以下错误:
2015-05-12T11:21:19.619-0700 E QUERY    ReferenceError: testdb is not defined
    at (shell):1:1

应该是 db.createCollection("testcollection") - Ori Dar
1个回答

7
正确的方式是使用 db.createCollection() 方法,您的代码失败是因为在您的调用 testdb.createCollection(testcollection) 中,testdb 不是 mongodb 对象。请尝试以下操作:
> use testdb
switched to db testdb
> db.createCollection("testcollection")
{ "ok" : 1 }
> db.getCollectionNames()
[ "system.indexes", "testcollection" ]
>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接