1

I want to find a document with x larger than the size of the array y. I'm doing this:

db.find(x: { $gt: { $size: "$y" } })

Doesn't find anything. What is wrong?

The last document should be returned:

{x: 0, y: [0, 1]}
{x: 1, y: [0, 1]}
{x: 2, y: [0, 1]}
{x: 3, y: [0, 1]} # 3 is larger than 2

1 Answer 1

1

You need $expr to compare two fields from the same document in your query:

db.col.find({ $expr: { $gt: [ "$x", { $size: "$y" } ] } })
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.