Mongodb - Use a regex search to match embedded documents -


i have mongo collection :

db.scriteria.insert({criteria : {a:"1",b:"2",c:"3"}}) db.scriteria.insert({criteria : {a:"1",d:"2",e:"3"}}) 

the properties of embedded document "criteria" can vary lot chose index whole object :

db.scriteria.ensureindex({criteria : 1}) 

and queries against entire object use index. ex :

db.scriteria.find({criteria : {a:"1",b:"2",c:"3"}}).count()  1 db.scriteria.find({criteria : {a:"1",b:"2"}}).count()  0 

what want able use regex property. example :

db.scriteria.find({criteria : {a:"1",b:"2",c:/3/}}).count()  

this gives 0 results

is there way , use index?

your query may not return document if querying subdocument because field order matter.the best thing create coumpound indexes , use dot notation.

db.scriteria.count({ "criteria.a": "1", "criteria.b": "2", "criteria.c": /3/}) 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -