“errmsg”:“exception:$ unwind:字段路径末尾的值必须是数组”

时间:2014-03-03 02:00:26

标签: mongodb aggregation-framework

查询:

db.trace.aggregate([
    {$unwind:"$likes"},
    { $group : { _id : {"name" : "$name"}  } } 
]);

Mongo系列:

"likes" : [
    {
        "category" : "test1",
        "name" : "test1",
        "created_time" : "2014-01-08T20:50:02+0000",
        "id" : "14157481053234234"
    },
    {
        "category" : "Publisher",
        "name" : "City Pulse",
        "created_time" : "2014-01-06T22:46:19+0000",
        "id" : "169217625001"
    }
]

错误:

{
    "errmsg" : "exception: $unwind: value at end of field path must be an array",
    "code" : 15978,
    "ok" : 0
}

获取该对象不是数组的错误,但它是。

1 个答案:

答案 0 :(得分:4)

可能在一个或多个文档中likes不是数组。

检查:db.trace.find( { $where : "!Array.isArray(this.likes)" } )