1

Suppose I have a collection whose documents have this structure

{
   ...
   "ts": [NumberLong("5"), NumberLong("7")]
   ...
}

where ts is an array of two Long elements, where the second is strictly bigger than the first one.

I want to retrieve all documents where all the elements of the array ts are within a range (bigger than a value but smaller than another).

Suppose the range is between 4 and 9; I am trying this query, but I find unexpected results:

db.segments.find({$nor: [{ "ts": {$gt:9, $lt:4}}]}).toArray()

1 Answer 1

1

If you have fixed number of array length then you can use the index of array in query part,

db.segments.find({
  "ts.0": { $gt: 4 },
  "ts.1": { $lt: 9 }
}).toArray()

Playground

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.