[英]Meteor.js / MongoDB : finding a document's place in a collection
解决了,感谢Hubert OG!
我有一个具有人气属性的收藏,我这样做:
var x = collection.find({},{sort: {popularity: 1}})
然后我想通过这种特殊的排序来查找文档的位置(索引)(使用其ID)。
我怎样才能做到这一点? 我是否必须将游标转换为数组并循环遍历,还是流星内置了可以给我索引的任何内容?
非常感谢您,丹尼尔。
您可以发现有多少个文档具有较高的知名度:
var popularity = Documents.findOne(documentId).popularity;
var morePopular = Documents.find({popularity: {$gt: popularity}}).count();
如果我正确理解:)
var first = collection.find({}).fetch();
var x = collection.find({},{sort: {popularity: 1}}).fetch();
for(var m=0; m<x.length;m++){
console.log(first.indexOf(x[m].fieldName))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.