2

I'm using official Mongo C# driver. As suggested in answer to one question I'm using the following for the 'like' operator -

Query.Matches("name", "Joe");

My question is how can I achieve the 'NotLike' functionality ?

1 Answer 1

4

Assuming you are using the new Query builder in version 1.5, you would do it this way:

var query = Query.Not(Query.Matches("name", "Joe"));

In version 1.5 we also introduced a new typed Query builder, which you could use this way:

var query = Query.Not(Query<C>.Matches(x => x.Name, "Joe"));

Finally, you could also write a LINQ query:

var query = collection.AsQueryable<C>().Where(x => !Regex.IsMatch(x.Name, "Joe"));
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Robert for always helping out so quickly

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.