Rick Strahl
Rick Strahl

Reputation: 17651

How to link multiple Query Operations in MongoDb C# Driver

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?

Upvotes: 1

Views: 1610

Answers (1)

Ben Allred
Ben Allred

Reputation: 4864

You need to nest the query operators. Something like this

Query.Or(Query.EQ("t", "F"), Query.EQ("t", "M"))

Upvotes: 2

Related Questions