Question

Basically the question is simple:

How can I issue a query on a collection, which starts with _?

For example if I have 2 collections test and _test, and I am trying db.test.findOne() and db._test.findOne() in mongoshell the first one is working as intended, whereas the second tells me TypeError: db._testhas no properties (shell):1

Était-ce utile?

La solution

Place it in quotes and use the getCollection method. See this article

Example To create a collection _foo and insert the { a : 1 } document, use the following operation:

db.getCollection("_foo").insert( { a : 1 } )

To perform a query, use the find() method, in as the following:

db.getCollection("_foo").find()
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top