Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB create collection failure

Tags:

mongodb

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
like image 945
hrishikeshp19 Avatar asked Aug 20 '26 11:08

hrishikeshp19


1 Answers

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" ]
>
like image 167
chridam Avatar answered Aug 24 '26 01:08

chridam