M.Z.
M.Z.

Reputation: 401

"errmsg" : "exception: $unwind: value at end of field path must be an array"

Query:

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

Mongo collection:

"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"
    }
]

Error:

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

Getting error that object is not array, but it is.

Upvotes: 3

Views: 3102

Answers (1)

Ivan.Srb
Ivan.Srb

Reputation: 1851

May be in one or more documents likes is not array.

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

Upvotes: 4

Related Questions