1

I've got a mongo object that follows this pattern. Actions is an array of objects. I've excluded the irrelevant fields.

{
  "_id" : 141,
  ...
  "Actions" : [{
      ...
      "Modified" : new Date("Thu, 29 Nov 2012 14:41:20 GMT -08:00"),
      ...
    }]
  ...
}

How do I query this so that I can get a list of objects which contain an object in the actions array who's modified property falls between a date range using the C# Mongo Driver.

1 Answer 1

1

I figured this out myself.

Query.ElemMatch("Actions",
    Query.And(
        Query.GTE("Modified", start),
        Query.LTE("Modified", end)
    )
)

Using a Query.ElemMatch against the Actions field passing in the Query for the Sub Elements.

Worked like a charm.

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.