Javascript Meteor.js/MongoDB:查找文档';他在收藏中的地位
多亏了Hubert OG强> 我有一个具有受欢迎属性的集合,我做了一个:Javascript Meteor.js/MongoDB:查找文档';他在收藏中的地位,javascript,mongodb,meteor,Javascript,Mongodb,Meteor,多亏了Hubert OG 我有一个具有受欢迎属性的集合,我做了一个: var x = collection.find({},{sort: {popularity: 1}}) 然后我想通过这个特殊的排序找到文档的位置(索引)(使用它的id) 我该怎么做?我是否必须将光标转换为数组并在其中循环,或者meteor中是否内置了任何可以为我提供索引的内容 丹尼尔,非常感谢您。您可以了解有多少文档更受欢迎: var popularity = Documents.findOne(documentId).po
var x = collection.find({},{sort: {popularity: 1}})
然后我想通过这个特殊的排序找到文档的位置(索引)(使用它的id)
我该怎么做?我是否必须将光标转换为数组并在其中循环,或者meteor中是否内置了任何可以为我提供索引的内容
丹尼尔,非常感谢您。您可以了解有多少文档更受欢迎:
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();
对于(var m=0;m
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))
}