鍍金池/ 問答/數(shù)據(jù)庫/ mongodb find 數(shù)組類型

mongodb find 數(shù)組類型

有這樣一組數(shù)據(jù),想find到第二組,即數(shù)組類型數(shù)據(jù),合適的查詢條件時什么

{
    "_id" : ObjectId("57986ddab806c2490e67abdc"),
    "test" : "this a test",
}

{
    "_id" : ObjectId("57986ddab806c2490e67abdd"),
    "test" : [
        "this a test"
    ],
}

自己使用$type,但只能find到如下結(jié)構(gòu)的

//find
db.data.find( { test: { $type: “array” } } )
//result
{
    "_id" : ObjectId("57986ddab806c2490e67abdd"),
    "test" : [
    [
                "this a test"
    ]
    ],
}
回答
編輯回答
久礙你

使用字段數(shù)組長度條件滿足了需求

db.data.find( { test: { $size: 1 } } )
2018年4月21日 21:35