2

There are already several questions, like this and this which answer how to use a Mongo collection with a dash in the name.

The suggestion is to use block notation, which works fine for dashes.

db["dash-collection"].count();

However if your collection is named "_sys/config" this trick won't work.

How can you access this collection from the shell?

Community
  • 1
  • 1
Mel Nicholson
  • 3,225
  • 14
  • 24

1 Answers1

4

This collection can still be accessed using method notation.

db.getCollection("_sys/config").count();

Credit to Ben Frank for finding this.

Mel Nicholson
  • 3,225
  • 14
  • 24
  • it's also in the docs here: http://docs.mongodb.org/manual/reference/limits/#naming-restrictions – Asya Kamsky Dec 13 '13 at 23:51
  • @asya This link doesn't show method notation for getting around the problem, it just has a non-binding suggestion not to use the slash in the first place. When dropped into an existing project that has already disregarded that advice, this is the way to cope. – Mel Nicholson Mar 04 '14 at 20:55
  • I see a note on that page that says "In the mongo shell, use db.getCollection() to specify collection names that might interact with the shell or are not valid JavaScript." is that not visible to you? – Asya Kamsky Mar 05 '14 at 03:19
  • @asya You are right...now I see it. They buried that pretty well. "In the mongo shell, use db.getCollection() to specify collection names that might interact with the shell or are not valid JavaScript." – Mel Nicholson Mar 05 '14 at 23:21