Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Meteor.js/MongoDB:查找文档';他在收藏中的地位_Javascript_Mongodb_Meteor - Fatal编程技术网

Javascript Meteor.js/MongoDB:查找文档';他在收藏中的地位

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

多亏了Hubert OG

我有一个具有受欢迎属性的集合,我做了一个:

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))
}