タグの数でソートされた出版物のリストを取得しようとしています。私はいくつかの作業を行っていますが、$unwind
オペレーターはタグのない出版物を消し去ります。私は成功せずにそれをバイパスするためにプレースホルダーを追加しようとしました:
Publication.collection.aggregate(
{ "$project" => { tags: { "$push" => "holder" } } },
{ "$unwind" => '$tags' },
{ "$group" => { _id: '$_id', count: { "$sum" => 1 } } },
{ "$sort" => { count: 1 } }
)
私が得た:
failed with error 15999: "exception: invalid operator '$push'"
ドキュメントの例:
{ _id: '1', tags: ['b','c'] }
{ _id: '2', tags: ['a'] }
{ _id: '3' }
何か案は?