For example we have collection
{field: {subfield: 'name'}}
{field: {subfield: 'phone'}}
Can I find document without dot notation? Like this
db.test.find({field: {subfield: /regex/}})
or maybe like this
db.test.find({field: {$someOperator: {subfield: /regex/}}})
I just don't want to build dot notation like
db.test.find({"field.subfield": /regex/})
The problem is that:
db.test.find({field: {$someOperator: {subfield: /regex/}}})
Is actually another way of querying in MongoDB which uses object euqality to search for subdocuments.
So no, you must use dot notation unless you were searching for where one object exactly equals the other.
That being said you could wrap the document in $elemMatch
: http://docs.mongodb.org/manual/reference/operator/elemMatch/ that would work
Considering you collection structure $elemMatch
won't actually work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With