How to check if a collection exist ?

4,135 views
Skip to first unread message

Thibaut Barrère

unread,
Sep 20, 2010, 8:57:31 AM9/20/10
to mongodb-user
Hi,

I'm trying to detect if a collection exist before renaming it
(renaming an non existing collection raises Error renaming collection:
{"errmsg"=>"exception: source namespace does not exist",
"code"=>10026, "ok"=>0.0}).

I could not find a function to achieve this (through the Ruby driver
at least). Is it possible in some way ?

cheers,

-- Thibaut

Kristina Chodorow

unread,
Sep 20, 2010, 9:45:46 AM9/20/10
to mongod...@googlegroups.com
You can query the system.namespaces collection of whichever db you're using.  Each collection in the db is listed there.



--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


Thibaut Barrère

unread,
Sep 20, 2010, 9:47:05 AM9/20/10
to mongodb-user
Hi Kristina,

> You can query the system.namespaces collection of whichever db you're
> using.  Each collection in the db is listed there.

thanks, I hadn't thought about that.

best,

-- Thibaut
Reply all
Reply to author
Forward
0 new messages