我目前正在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);
});
}
});

这是我的cmd在Meteor运行应用程序时的样子,我想autopublish错误是有意义的,但我不知道如何使用这些信息。
答案 0 :(得分:1)
尝试使用写入命令 Live Demo ,这些命令允许执行批量插入操作,这些操作只是服务器顶部的抽象操作,并且可以轻松构建批量操作。这些批量操作主要有两种形式:
要使用批量api,您需要通过Mongo.Collection上的rawCollection和rawDatabase方法获取npm MongoDB驱动程序中的集合和数据库对象的原始访问权限。
以下演示了这种方法:
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
});
}
}
});
}