I'm using MongoDB to store a bunch of information, and need to search an indexed array for values.
Here's the schema:
{ "common_name" : { "name" : "thename", "type" : "thetype" } }
There are other values in the document, but this is the only one I'm searching.
So, I figured something like this would work: (in the shell)
db.collection.find({common_name:{$in:"thename"}})
But I get nothing back.
This looks like exactly like what is being done here: http://www.php.net/manual/en/mongo.queries.php - But I can't seem to get anything back.
I've tried
db.collection.find({"common_name.name":"thename"}})
and it works as expected, but to search multiple nodes on the index (up to 4), it could get ugly, basically defining an $or index for each subcategory, and quadrupling my query time. Being that this is powering an autocompleter, I can't do that.
Oddly enough, the following doesn't return any documents either:
db.collection.find({"common_name":{"name":"thename"}})
Which to my understanding, is exactly the same thing as the above query.
I'm pretty new to Mongo, so maybe I'm missing something big here?
Any ideas as to how to get the fastest access to this data (using an anchored regex)?
I could just use a relational table, but doesn't that defeat the purpose of a NoSQL system like Mongo?