I have the following query db in mongodb that returns exactly what I need:
db.collection.find({field1: 2801394}, {name: 1, field2: 1, _id: 1, "field3.2801394": 1})
Note field 3 is a hash, and the key used here is the same as for field1 by the value in field 1.
How can I convert this query to mongoid? There are two main issues here, and I can't find anything online for either one individually:
Thanks!
For filtering out/projecting one or more fields, you can use Queryable.only found at http://mongoid.org/en/origin/docs/options.html.
The example given on that page:
queryable.only(:name, :age)
For nested fields, you could use strings instead of symbols in the parameters:
queryable.only(:name, :field2, :_id, 'field3.2801394')
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