Javascript Meteor:从MongoCollection.find()遍历光标并打印字段

Javascript Meteor:从MongoCollection.find()遍历光标并打印字段,javascript,mongodb,meteor,handlebars.js,Javascript,Mongodb,Meteor,Handlebars.js,我无法打印从流星收藏中获得的内容。我已经在/ui/api/collections.js中声明了我的集合 import { Meteor } from 'meteor/meteor'; import { Mongo } from 'meteor/mongo'; import 'meteor/aldeed:collection2'; export const Courses = new Mongo.Collection("courses"); Courses.allow({ 'inser

我无法打印从流星收藏中获得的内容。我已经在/ui/api/collections.js中声明了我的集合

import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import 'meteor/aldeed:collection2';

export const Courses = new Mongo.Collection("courses");

Courses.allow({
    'insert': function () {
       // if (Meteor.isEducator(Meteor.userId())) {
            return true;
    }
})
/导入/api/course.html

<template name="course">
    <h2> You are enrolled in the following courses:</h2>
    <ul>
        {{#each course_list}}
            {{> getCourseName}}
        {{/each}}
    </ul>
</template>

<template name="getCourseName">
    <li><h2>{{courseName}}</h2></li>
</template>
我将Courses声明为一个新的Mongo.Collection,并将其导入/server/main.js,然后将/imports/api/collections.js导入course.js和course.html

the console output of printing course_list's result is :
L…n.Cursor {collection: LocalCollection, sorter: null, matcher: M…o.Matcher, _selectorId: undefined, skip: undefined…}

我注意到它说的是LocalCollection,这让我觉得它找不到实际的集合。在服务器端mongo控制台上执行db.courses.find()时,我看到集合中确实存在两个课程,它们都有一个courseName字段。我不认为我需要发布/订阅,因为我在导入中声明集合,然后将集合导出为全局变量。我一般不熟悉meteor和javascript,因此非常感谢您的任何解释。

不用担心。您已经可以访问数据了。只是Meteor在客户端创造了Minimongo的力量。这就是为什么您在控制台上看到的是
LocalCollection
,而不是您可能期望的
Courses

还请注意,集合上的
find
返回一个值。需要使用fetch、forEach、map等操作来操作实际数据

the console output of printing course_list's result is :
L…n.Cursor {collection: LocalCollection, sorter: null, matcher: M…o.Matcher, _selectorId: undefined, skip: undefined…}