I am currently working on a application in Meteor where I read Data out of an Collection from MongoDB, in which i of course put data in, and save this data into a tabular table. But the problem is, that after the first start of the app the Data doesnt refresh in the table, only the table header refresh, not the entries. This is my code i currently have.
我目前正在研究Meteor中的一个应用程序,我从MongoDB读取一个Collection中的数据,当然我将数据放入其中,并将这些数据保存到表格表中。但问题是,在第一次启动应用程序后,数据不会在表中刷新,只有表头刷新,而不是条目。这是我目前拥有的代码。
//common.js
//code shared between client and server
Books = new Mongo.Collection("user");
TabularTables = {};
Meteor.isClient && Template.registerHelper('TabularTables', TabularTables);
TabularTables.Books = new Tabular.Table({
name: "wahltable",
collection: Books,
columns: [
{data: "vname", title: "Vorname"},
{data: "nname", title: "Nachname"},
{data: "standort", title: "Standort"},
{data: "stimmen", title: "Stimmen"},
{data: "anmerkung", title: "Anmerkung"}
]
});
//app.js from the server
Meteor.startup(function () {
if (Books.find().count() === 0) {
var books = [
{vname: "Anna", nname: "Muster" ,standort: "Das Modul", stimmen:"4", anmerkung:"nichts"},
{vname: "Peter", nname: "Meier" ,standort: "BMHS", stimmen:"45", anmerkung:"nichts"},
{vname: "Max", nname: "Muster" ,standort: "BMHS", stimmen:"66", anmerkung:"nichts"},
{vname: "Moritz", nname: "Kaiser" ,standort: "BMHS", stimmen:"90", anmerkung:"nichts"},
{vname: "Niklas", nname: "König" ,standort: "BMHS", stimmen:"123", anmerkung:"nichts"},
{vname: "Victoria", nname: "Berger" ,standort: "TGM", stimmen:"90", anmerkung:"nichts"},
{vname: "Hans", nname: "Berger" ,standort: "TGM", stimmen:"90", anmerkung:"nichts"},
{vname: "Sepp", nname: "Hund" ,standort: "TGM", stimmen:"30", anmerkung:"nichts"},
{vname: "Franz", nname: "Kross" ,standort: "TGM", stimmen:"940", anmerkung:"nichts"},
{vname: "Miriam", nname: "Mayer" ,standort: "TGM", stimmen:"20", anmerkung:"nichts"},
{vname: "Sandra", nname: "Meier" ,standort: "TGM", stimmen:"12", anmerkung:"nichts"},
];
_.each(books, function (book) {
Books.insert(book);
});
}
});
This is how my cmd looks like while Meteor is running the app, i guess the autopublish error is meaningful but i dont know how to use this information.
这就是我的cmd在Meteor运行应用程序时的样子,我想autopublish错误是有意义的,但我不知道如何使用这些信息。
1 个解决方案
#1
1
Try using a write commands Bulk API that allow for the execution of bulk insert operations which are simply abstractions on top of the server and they make it easy to build bulk operations. These bulk operations come mainly in two flavours:
尝试使用写入命令批量API,允许执行批量插入操作,这些操作只是服务器顶部的抽象操作,并且可以轻松构建批量操作。这些批量操作主要有两种形式:
- Ordered bulk operations - These operations execute all the operation in order and error out on the first write error.
- Unordered bulk operations - These operations execute all the operations in parallel and aggregates up all the errors. Unordered bulk operations do not guarantee order of execution.
有序批量操作 - 这些操作按顺序执行所有操作,并在第一次写入错误时出错。
无序批量操作 - 这些操作并行执行所有操作并聚合所有错误。无序批量操作不保证执行顺序。
To use the bulk api, you need to get raw access to the collection and database objects in the npm MongoDB driver through rawCollection and rawDatabase methods on Mongo.Collection.
要使用批量api,您需要通过Mongo.Collection上的rawCollection和rawDatabase方法获取npm MongoDB驱动程序中的集合和数据库对象的原始访问权限。
The following demonstrates this approach:
以下演示了这种方法:
Books = new Meteor.Collection('books');
if (Meteor.isServer) {
Meteor.startup(function () {
if (Books.find({}).count() === 0) {
var bulkOp = Books.rawCollection().initializeUnorderedBulkOp(),
counter = 0,
books = [...]; // the books data array, shortened for brevity
_.each(books, function (book) {
bulkOp.insert(book);
counter++;
if (counter % 1000 == 0) {
// Execute per 1000 operations and re-initialize every 1000 update statements
bulkOp.execute(function(e, rresult) {
// do something with result
});
bulkOp = Books.rawCollection().initializeUnorderedBulkOp();
}
});
// Clean up queues
if (counter % 1000 != 0){
bulkOp.execute(function(e, result) {
// do something with result
});
}
}
});
}
#1
1
Try using a write commands Bulk API that allow for the execution of bulk insert operations which are simply abstractions on top of the server and they make it easy to build bulk operations. These bulk operations come mainly in two flavours:
尝试使用写入命令批量API,允许执行批量插入操作,这些操作只是服务器顶部的抽象操作,并且可以轻松构建批量操作。这些批量操作主要有两种形式:
- Ordered bulk operations - These operations execute all the operation in order and error out on the first write error.
- Unordered bulk operations - These operations execute all the operations in parallel and aggregates up all the errors. Unordered bulk operations do not guarantee order of execution.
有序批量操作 - 这些操作按顺序执行所有操作,并在第一次写入错误时出错。
无序批量操作 - 这些操作并行执行所有操作并聚合所有错误。无序批量操作不保证执行顺序。
To use the bulk api, you need to get raw access to the collection and database objects in the npm MongoDB driver through rawCollection and rawDatabase methods on Mongo.Collection.
要使用批量api,您需要通过Mongo.Collection上的rawCollection和rawDatabase方法获取npm MongoDB驱动程序中的集合和数据库对象的原始访问权限。
The following demonstrates this approach:
以下演示了这种方法:
Books = new Meteor.Collection('books');
if (Meteor.isServer) {
Meteor.startup(function () {
if (Books.find({}).count() === 0) {
var bulkOp = Books.rawCollection().initializeUnorderedBulkOp(),
counter = 0,
books = [...]; // the books data array, shortened for brevity
_.each(books, function (book) {
bulkOp.insert(book);
counter++;
if (counter % 1000 == 0) {
// Execute per 1000 operations and re-initialize every 1000 update statements
bulkOp.execute(function(e, rresult) {
// do something with result
});
bulkOp = Books.rawCollection().initializeUnorderedBulkOp();
}
});
// Clean up queues
if (counter % 1000 != 0){
bulkOp.execute(function(e, result) {
// do something with result
});
}
}
});
}