Reputation: 9028
I am trying to
1. Create a database
use testdb switched to db testdb
2. Create collection
testdb.createCollection(testcollection)
I am getting following error:
2015-05-12T11:21:19.619-0700 E QUERY ReferenceError: testdb is not defined
at (shell):1:1
Upvotes: 3
Views: 6802
Reputation: 103355
The correct way is by using the db.createCollection()
method, your code fails because testdb
is not a mongodb object in your call testdb.createCollection(testcollection)
. Try the following:
> use testdb
switched to db testdb
> db.createCollection("testcollection")
{ "ok" : 1 }
> db.getCollectionNames()
[ "system.indexes", "testcollection" ]
>
Upvotes: 7