0

I'm trying to write up a mongo query that finds all entries where the "steps" field has no values within an array argument.

So for example, given two entries with values:

Entry1:
  steps: [3, 4]

Entry2:
  steps: [3, 5]

The query should return entry1, but not entry 2, for input array [4, 8, 10]. I'm quite new to mongo - any ideas appreciated.

1
  • Post your query and some sample document. It's better to understand and give suggestion. Commented Mar 7, 2013 at 9:59

1 Answer 1

1

You mean you have some records:

db.foo.find() { "_id" : 1, "steps" : [ 3, 4 ] } { "_id" : 2, "steps" : [ 3, 5 ] }

Then you would query:

> db.foo.find({steps:{$in:[4,8,10]}})
{ "_id" : 1, "steps" : [ 3, 4 ] }

the $in clause will pick records in which any stored element matches any of terms in the array supplied in the query

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.