0

i have collection called "devices". this devices collection have two fields called as "devices" and "totalDeviceNeeds". totalDeviceNeeds have integer value. devices field contain array. I want to get all documents that totalDeviceNeeds > devices array size. How can i do that. I try lot of ways and didnt get correct. I try in nodejs.

2
  • Did you try the $where operator? Something like this, db.devices.find( { $where: "this.totalDeviceNeeds > this.devices.length" } ); Commented Aug 15, 2021 at 16:49
  • yah but not luck Commented Aug 15, 2021 at 17:18

1 Answer 1

1

Thank you all.

i just wrote query code or whatever called. here is this

db.collection.find({ $expr:{ $lt:[{$size:"$devices"}, "$totalDeviceNeeds"] } }).toArray();

in this $lt meaning less than operation

i used this post to do this.

https://www.mongodb.com/community/forums/t/is-there-a-way-to-query-array-fields-with-size-greater-than-some-specified-value/54597/2

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.