0

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?

1 Answer 1

2

Try:

HistoryTracker.where("modified.company_id" => Moped::BSON::ObjectId("51f654a099c655032a000002")}).count
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.