collection exists

25 views
Skip to first unread message

mongobee

unread,
Sep 11, 2012, 12:38:45 AM9/11/12
to mongod...@googlegroups.com
I want to check first whether a collection exists or  not. how can i do this?
 
db.firstcollection.find({$exists:false}) - doesn't seem to work.

mongobee

unread,
Sep 11, 2012, 12:39:50 AM9/11/12
to mongod...@googlegroups.com
Also default database is db. what if i want to have different databases?

Stephen Steneker

unread,
Sep 11, 2012, 12:49:26 AM9/11/12
to mongod...@googlegroups.com
I want to check first whether a collection exists or  not. how can i do this?
 
db.firstcollection.find({$exists:false}) - doesn't seem to work.

Hi,

You can use:
 db.getCollectionNames() 

> Also default database is db. what if i want to have different databases?

Just "use dbname" (where dbname is the name of another database).  The database is created the first time data is inserted.


Since you are new to MongoDB, it would be worth having a run through the tutorial:
 http://www.mongodb.org/display/DOCS/Tutorial

There is also a short interactive tutorial:
 http://try.mongodb.org/

Cheers,
Stephen

mongobee

unread,
Sep 11, 2012, 1:05:08 AM9/11/12
to mongod...@googlegroups.com
got it. thanks Stephan.
Reply all
Reply to author
Forward
0 new messages