1

I have read the documentation and searched all over but I can't find how to do it. If I have a document inside a collection and the document is an empty array I can remove it like this:

db.data.remove(array('document'=>array()))

or like this:

db.data.remove(array('document'=>[]))

But if the array is not empty it doesn't work, so I tried like this:

db.data.remove(array('document'=>array('$type'=>4)))

Am I doing it wrong? Is there any way to do this? Removing the document on another criteria isn't useful for me.

4

1 回答 1

2

编辑: 最后我发现你的问题是什么。

// test document
{ "_id" : ObjectId("4fe1af4dd404b1863ff20aac"), "document" : [ 1 ] }

运算符查看数组内部,而$type不是数组本身,因此以下 find 不返回任何内容:

db.test.find({document : { $type : 4  } })

现在在我的测试用例中,该文档包含一个双精度,以下查找返回该文档:

db.test.find({document : { $type : 1  } })
{ "_id" : ObjectId("4fe1af4dd404b1863ff20aac"), "document" : [ 1 ] }

另请参阅有关此主题的错误报告: https ://jira.mongodb.org/browse/SERVER-1475

于 2012-06-20T11:12:04.747 回答