Two collection with same name

I created a collection named myMovies from compass and ran db.myMovies.insertMany( …) from shell. That created another collection with same name and few documents gets created though didn’t update in which I created from Compass .

image

Looks like a simple display glitch. Try the refresh icon. Or View->Reload to reconnect to your server.

Another idea, may be the one created from Compass has a space character at the end, which of course cannot be seen from the view.

I can see it :lying_face:

And I wonder what “movies You Love@Abir_19748 :grin:

I was able to create ‘myMovies’ and 'myMovies '. That is one with a trailing space and one without one. That’s probably what happen.

1 Like

Hi @Abir_19748,

Thanks for surfacing the issue. I have forwarded it to the relevant team.

As @steevej-1495 mentioned due to some trailing spaces it created two collections. The collection in which you inserted the documents should display size in the Total Document Size column. For the ones which are empty will have 0.0 B size.

If you have any other issue please feel free to get back to us.

Thanks,
Shubham Ranjan
Curriculum Support Engineer

Hi @steevej-1495 thanks for your help, extra trailing space was there and was confirmed when I was trying to drop the collection and I had to type 'myMovies ’ to drop that with extra space :smiley:

Another thing I would like to ask for help here is, I have other 2 collection ‘movies I love’ & ‘moviesIlove’ as you see in above screenshot, when trying to insertMany() I get syntax error for ‘movies I love’ as below but successfully updates value within ‘moviesIlove’.

It is the space again. The space is a token separator in js/mongo-shell. The only way I was able to do something like that was with

c = "movies I love"
db.c.insertMany( ... )

Perhaps if you treat it as an array:
db["movies I love"].insertMany(...)

Edit: In Python terminology, dictionaries.

Hi @Abir_19748,

In addition to @steevej-1495 and @007_jb,

You can also use the db.getCollection() method.

db.getCollection("movies I love").insertMany([...])

By the way, did you notice that your insertMany() with ordered parameter set to false only inserted 4 documents whereas you passed 5 documents in the array ? :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Support Engineer

When I returned to cleanup what I did I found out that

did not really worked. 8-( There was no error but the collection created was named c, not movies I love. The variable was not expanded.

Yes, thanks :slight_smile:

thanks for your input @steevej-1495

ha ha , not in here @007_jb