Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb querying collection starting with _

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

like image 385
Salvador Dali Avatar asked Jul 28 '13 01:07

Salvador Dali


1 Answers

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()
like image 76
What Would Be Cool Avatar answered Sep 28 '22 11:09

What Would Be Cool