这个想法是为了在mongodb的聚合命令/管道中返回一种行号,类似于关系型数据库中所使用的。它应该是一个唯一的数字,如果它与行数完全匹配则不重要。
对于如下查询:
[ { $match: { "author" : { $ne: 1 } } }, { $limit: 1000000 } ]
我想要退货:
{ "rownum" : 0, "title" : "The Banquet", "author" : "Dante", "copies" : 2 }
{ "rownum" : 1, "title" : "Divine Comedy", "author" : "Dante", "copies" : 1 }
{ "rownum" : 2, "title" : "Eclogues", "author" : "Dante", "copies" : 2 }
{ "rownum" : 3, "title" : "The Odyssey", "author" : "Homer", "copies" : 10 }
{ "rownum" : 4, "title" : "Iliad", "author" : "Homer", "copies" : 10 }
在 MongoDB 中是否有可能生成这个 rownum
?