remove documents with array field's size less than 3 in mongoDB
mongodb, mongodb-query
Solution
From the documentation for `$size`:
You cannot use $size to find a range of sizes (for example: arrays with more than 1 element).
The docs recommend maintaining a separate size field (so in this case, arrFieldSize) with the count of the items in the array if you want to try this sort of thing.
Problem
i have a mongoDB collection named `col` that has documents that look like this ``` { { intField:123, strField:'hi', arrField:[1,2,3] }, { intField:12, strField:'hello', arrField:[1,2,3,4] }, { intField:125, strField:'hell', arrField:[1] } } ``` Now i want to remove documents from collection `col` in which `size` of the array field is less than 2. So i wrote a query that looks like this ``` db.col.remove({'arrField':{"$size":{"$lt":2}}}) ``` Now this query doesnt do anything. i checked with `db.col.find()` and it returns all the documents. Whats wrong with this query?