0

I need to have a query as such

Query.And(Query.NE("name", name[0]), Query.NE("name", name[1]));

However I don't know the number of elements in name[] and I need to make a AND of NE of all elements of name[].

Is there a way to build it?

3
  • what tool are you using? (What/where is Query coming from?) I'd expect you'd find your answer by searching a little more. Here's a random cheat sheet layerworks.com/blog/2014/11/11/… Commented Aug 12, 2016 at 14:16
  • thanks for your answer. I'm using MongoDB.Driver.Builders.Query Commented Aug 12, 2016 at 14:26
  • You likely want to be using $nin here instead; that way you don't have to build your query dynamically and it will be more efficient. Commented Aug 12, 2016 at 14:33

1 Answer 1

1

The Query.AND() method signature takes IEnumerable<IMongoQuery> parameter type so you could write your method as follows for any number of items:

Query.AND(name.Select( x=> Query.NE("name", x));
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.