2013-08-30 29 views
1
I have a collection having following data: 

{"_id" : ObjectId("5220222f8188d30ce85d61cc"), 

“testfields”:[{ “为test_id”:1, “TEST_NAME”: “XXXX” }] }

when I query : 
db.testarray.find({ "testfields" : { "$type" : 4 } }) 

it returns no data,but same returns data when I do: 
db.testarray.find({ "$where" : "Array.isArray(this.testfields)" }) 

It returns data, do the type:4 identifies some other kind of list? 

回答

1

因为testfieldsArray,$type : 4将对testfields中的每个元素执行“is array”检查,而不是testfields本身。由于您的testfields只包含一个Object,因此不会返回。

如果在另一方面,你插入以下到您的收藏,

db.testarray.insert({ "testfields" : [ { "test_id" : 1, "test_name" : "xxxx" }, 
             [ "a", "b" ] ] }); 

它会得到恢复,因为现在的testfields的要素之一是Array

更多信息可在docs解释。

+0

thanx,但我想只检查它的testfields。我无法使用$,因为它不适用于$匹配。 –