1

I'm trying to create a complex query expression with the MongoDb C# driver. So far I've mostly relied on the LINQ .AsQueryable() features which work great, but now I need to run some update operations and it looks like I need to use the QueryBuilder for that.

However, I can't figure out how to create a complex query that strings multiple query operators together.

I'd like to do something like this:

var query = Query<QueueMessageItem>
            .EQ( qi => qi.Type, queueName)
            .EQ("Started", null);

but apparently this doesn't work because .EQ() and all the other query operators don't return a chainable Query object.

How do I use Queries and add multiple search operators?

3
  • Have you tried nesting them (Query.Or(Query.EQ("t", "F"), Query.EQ("t", "M")))? Commented Feb 27, 2014 at 20:15
  • Nope - and I missed it because Query<T> doesn't have it. Yes that'll work, but shame that the driver can't chain which would be way more natural. Commented Feb 27, 2014 at 20:18
  • Agreed, on fluent chaining. BTW, love your blog. Commented Feb 27, 2014 at 20:20

1 Answer 1

2

You need to nest the query operators. Something like this

Query.Or(Query.EQ("t", "F"), Query.EQ("t", "M"))
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.