- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在打印从 meteor 收藏中获得的内容时遇到问题。我已在/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;
}
})
/imports/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>
/imports/api/course.js
Template.course.helpers({
course_list: function() {
var result = Courses.find({});
console.log("result is:");
console.log(result);
return result;
}
})
我已将 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() 时,我看到集合中确实存在两个类(class),并且它们都有一个 courseName 字段。我认为我不需要发布/订阅,因为我在导入中声明集合,然后将集合导出为全局变量。一般来说,我对meteor和javascript都很陌生,所以非常感谢任何解释。
最佳答案
不用担心。您已经可以访问数据了。只是Meteor创造了local collections在客户端 - Minimongo 的力量。这就是为什么您在控制台上看到的是 LocalCollection
,而不是您所期望的 Courses
。
另请注意,集合上的 find
返回 cursor 。需要使用fetch、forEach、map等操作来操作实际数据。
关于javascript - Meteor:从 MongoCollection.find() 遍历光标并打印字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38625169/
嗨,我不知道如何为它起一个好的标题,但我相信你会理解的 因此,当用户单击按钮时,我尝试在我的 Mongo 集合上设置 2 个字段,但每隔 60sc 我就会有一个正在运行的方法以及是谁执行的: up
我想知道是否可以在 MongoDB 中重新搜索数组中的集合文档。就像这个例子: Mongo的JSON { value1 : "aaa", arrayvalue : [{ value2 : "a
我有一个 MongoCollection。我想遍历每个项目。通常我做一个游标,选择一些带有查询的项目。然后我通过游标循环以下内容: foreach (CMongoJob job
我正在使用如下所示的代码: if (collection.find(toFind) != null) { dataFound = collection.find(toFind)
使用 MongoDB 异步 Java 驱动程序时:以下回调需要使用 AtomicInteger 计数器还是普通的 int 来完成这项工作? Block theBlock = new Block() {
我目前正在与 MongoDriver 合作并且,根据 docs ,只有 MongoClient需要是单例。 那讲得通。但是,在研究过程中,我在 SO 上发现了一些旧帖子。 The accepted a
在经历了大量的examples之后,我找不到相关代码,基本上我想通过线路将 JSON 数组序列化到客户端。 MongoCursor cursor = ((MongoCollection)data).f
我正在尝试将 mongodb 集合中的单个文档更新为 JSONArray jsonArr = new JSONArray(); /*Some processing to add stuff to js
我正在尝试在 MongoCollection 中插入/更新许多记录。我有一份需要更新的文档列表。 List Documents; 该列表包含一些要插入的新记录以及其他需要更新的现有记录。我正在研究方法
我有一个 MongoCollection我在其中分配一个集合。我正在尝试通过他的 ID 查找用户。 user = (Document) usersCollection.find(new Documen
由于从 MongoDB 获取重复文档,我们在系统中遇到了一个错误。当使用 FindAll 同时从另一个进程更新集合时,会发生这种情况。 避免这种情况的最佳做法是什么? 我们不介意获取刚刚更新的文档的陈
我使用 Moq 来模拟 GetCollection 方法,但该行崩溃了。 var collectionSettings = new MongoCollectionSettings { Guid
什么时候应该使用 MongoCollection,什么时候使用 DBCollection?同样的问题也适用于 DBObject、BasicDBObject、Document。似乎有不同的东西是相似的。
我在打印从 meteor 收藏中获得的内容时遇到问题。我已在/ui/api/collections.js 中声明了我的集合 import { Meteor } from 'meteor/meteor'
我有一个名为 Employee 的类。从我的 Controller 我传递 IEnumerable查看。如何转换 MongoDB.Driver.MongoCollection至 IEnumerable
我试过在 Internet 上到处搜索,但终究找不到如何使用此方法。我曾尝试查看 mongo 控制台以将两者关联起来,但我的想法已经打败了我的大脑。任何人都可以帮助我解决这个问题或指出帮助的方向吗?
如文档中所述: http://mongodb.github.io/mongo-java-driver/3.3/driver/getting-started/quick-tour/ The MongoC
我正在尝试在 mongodb 中实现一个'server-side counter-versioned' 项并尝试执行以下操作/* 使用 Java API */ Document dbDoc = dbC
我有一些使用旧 1.x 版本的 MongoDB 驱动程序的 C# 代码,该驱动程序提供了使用 MongoCollection.Save() 方法的通用保存方法。但是在升级到 2.0 之后,这个方法似乎
我正在尝试将 spring-data-mongodb 从 1.5 升级到 2.1.0.M3所以我修改了pom依赖: org.springframework.data
我是一名优秀的程序员,十分优秀!