Reputation: 12618
I am using Rails 3.2.8, Mongoid 3.1.4 and Ruby 1.9.3
I have simple JSON:
{
_id: ObjectId("51f65be999c655122d0097ed"),
association_chain: [
{
name: "VendorForecast",
id: ObjectId("51f65be999c655122d0097ec")
}
],
scope: "vendor_forecast",
original: {},
modified: {
category_id: ObjectId("51f65b3799c655122d00008e"),
scenario_id: ObjectId("51f65b3799c655122d00002e"),
period_id: ObjectId("51bf800b99c655fe13000152"),
value: 150000,
company_id: ObjectId("51f65b3699c655122d000002")
},
version: 1,
action: "create",
modifier_id: ObjectId("51f65b3799c655122d000006"),
updated_at: ISODate("2013-07-29T12:11:21+00:00"),
created_at: ISODate("2013-07-29T12:11:21+00:00")
}
I want to get all models which have
modified: {
company_id: ObjectId("51f65b3699c655122d000002")
}
If I just query this by simple:
1.9.3p429 :026 > HistoryTracker.where(modified: {"company_id" => "51f654a099c655032a000002"}).size
=> 0
I get no results.
Any thought how to get this working?
Upvotes: 0
Views: 974
Reputation: 17803
Try:
HistoryTracker.where("modified.company_id" => Moped::BSON::ObjectId("51f654a099c655032a000002")}).count
Upvotes: 2