Multiple Collections with the same name

1,061 views
Skip to first unread message

Daniel W

unread,
Jun 27, 2011, 11:00:27 PM6/27/11
to mongodb-user
Somehow, I managed to create multiple collections with the same name,
which I thought was illegal:

> show collections
NY
NY
NY
PHONES
system.indexes
system.users

I'm using pymongo to import a lot of records into MongoDB. I have a
document with a single field, 'gotto', with an integer value of how
many records I have import already. The first time my python script
is run, however, the relevant collection doesn't yet exist, so I have
a try-except:

# Checking what record we made it to last run
try:
status = db.NY.find({ 'gotto' : { '$exists' : True}}).next()
except StopIteration:
#hasn't been made yet, better make it now
db.NY.insert({'gotto' : 0})
#and putting it into status
status = db.NY.find({ 'gotto' : { '$exists' : True}}).next()

In the course of debugging, I realized I had made multiple collections
called 'NY'

1. How did this happen?
2. How do I fix it? db.NY.drop() returns false.

Thanks-

Nat

unread,
Jun 28, 2011, 12:03:31 AM6/28/11
to mongod...@googlegroups.com
Can you try to get the output from shell? Your collection may have some blank spaces.

db.system.namespaces.find()

Daniel W

unread,
Jun 28, 2011, 2:14:16 AM6/28/11
to mongodb-user
After a couple of hours, I tried re-running the script and it worked.
Although the multiple collections with name 'NY' still existed,
queries all pointed the 'correct' one:

> show collections
NY
NY
NY
NY
PHONES
system.indexes
system.users
> db.NY.count()
81501

At this point, I did db.NY.drop(), it returned true, all the 'NY'
collections were deleted, and everything went back to normal. So
everything is OK now, I'm just a little spooked.
Nat, did you mean spaces in the collection name? I copied the above
bit from the shell, no spaces.

Mongolabs support found this: http://groups.google.com/group/mongodb-user/browse_thread/thread/69dfde6b64628928




On Jun 28, 2:03 pm, Nat <nat.lu...@gmail.com> wrote:
> Can you try to get the output from shell? Your collection may have some
> blank spaces.
>
>
>
>
>
>
>
> > *db.system.namespaces.find*()

Eliot Horowitz

unread,
Jun 28, 2011, 10:53:33 AM6/28/11
to mongod...@googlegroups.com
What version was this with?

> --
> 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.
>
>

Daniel W

unread,
Jun 29, 2011, 1:37:43 AM6/29/11
to mongodb-user
1.8.1

On Jun 29, 12:53 am, Eliot Horowitz <eliothorow...@gmail.com> wrote:
> What version was this with?
>
>
>
>
>
>
>
> On Tue, Jun 28, 2011 at 2:14 AM, Daniel W <dweitzenf...@gmail.com> wrote:
> > After a couple of hours, I tried re-running the script and it worked.
> > Although the multiple collections with name 'NY' still existed,
> > queries all pointed the 'correct' one:
>
> >> show collections
> > NY
> > NY
> > NY
> > NY
> > PHONES
> > system.indexes
> > system.users
> >> db.NY.count()
> > 81501
>
> > At this point, I did db.NY.drop(), it returned true, all the 'NY'
> > collections were deleted, and everything went back to normal.  So
> > everything is OK now, I'm just a little spooked.
> > Nat, did you mean spaces in the collection name?  I copied the above
> > bit from the shell, no spaces.
>
> > Mongolabs support found this:http://groups.google.com/group/mongodb-user/browse_thread/thread/69df...

Nat

unread,
Jun 29, 2011, 1:41:08 AM6/29/11
to mongod...@googlegroups.com
Do you have a way to reproduce the problem?

Daniel W

unread,
Jun 30, 2011, 2:04:21 AM6/30/11
to mongodb-user
Unfortunately, no.
As I mentioned, it was only that way for a few hours.
I'll be sure to write if it ever happens again.

Doug Paul

unread,
Mar 16, 2012, 2:43:31 PM3/16/12
to mongod...@googlegroups.com
I've run into the same problem.  Unfortunately, I can't past output.  When I do "show collections" or "db.getCollectionNames()", one of my collections (call it "problemCollection") shows up 23 times.  (And none of them have leading or trailing spaces.)  For example:

> db.getCollectionNames()
[
        "problemCollection",
        "problemCollection",
        .
        .
        .
        "problemCollection",
        "anotherCollection",
        "yetAnotherCollection"
]


Furthermore, I have a collection (call it "absentCollection") that doesn't show up in that list, but when I do "db.createCollection("absentCollection")", I get the error "collection already exists".

Anyone (Scott!) have any idea why the list of collections wouldn't match up with the collections that actually exist?  If anyone has any suggestions on commands to run to gather more information, I'm all ears.

Doug Paul

unread,
Mar 16, 2012, 2:45:58 PM3/16/12
to mongod...@googlegroups.com
I should also have mentioned that I'm running 1.8.1.

Doug Paul

unread,
Mar 16, 2012, 3:09:12 PM3/16/12
to mongod...@googlegroups.com
Some more info:

db.absentCollection.stats() does return the collection's stats, and they look normal.  However, db.absentCollection.exists() returns null.

db.system.namespaces.find() indeed shows problemCollection many times but does not show absentCollection.  (And no, I have never directly manipulated db.system.namespaces; I only knew about it from looking at the source for the exists function.)

Eliot Horowitz

unread,
Mar 17, 2012, 1:48:52 AM3/17/12
to mongod...@googlegroups.com
I would upgrade mongo and then do a repair if possible.

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.

> To view this discussion on the web visit
> https://groups.google.com/d/msg/mongodb-user/-/qNUvlVn_SxoJ.

Reply all
Reply to author
Forward
0 new messages