在mongoDB中删除数组字段大小小于3的文档 [英] remove documents with array field's size less than 3 in mongoDB
本文介绍了在mongoDB中删除数组字段大小小于3的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为col
的mongoDB集合,其中包含如下所示的文档
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]
}
}
现在,我想从数组字段size
小于2的集合col
中删除文档.
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}}})
现在此查询不执行任何操作.我用db.col.find()
检查过,它返回了所有文档.该查询出了什么问题?
Now this query doesnt do anything. i checked with db.col.find()
and it returns all the documents. Whats wrong with this query?
推荐答案
查看全文