如何构建一个查询,返回按嵌入式帖子 ID 计数排序的所有实体?
样本数据:
{ "_id" : ObjectId( "5090f8061e7bf28095000012" ),
"name" : "test",
"post_ids" :
[ ObjectId( "5090f8061e7bf28095000010" ) ],
[ ObjectId( "5090f8061e7bf28095000011" ) ] },
{ "_id" : ObjectId( "5090f8061e7bf28095000012" ),
"name" : "test2",
"post_ids" : [
ObjectId( "5090f8061e7bf28095000010" ),
ObjectId( "509104ec1e7bf2989b00000b" ),
ObjectId( "509105001e7bf2989b00000f" ) ] }
#my actual query returns only count:
tags_by_count = Tag.desc(:post_ids).count