I just started using meteor and I’m using the RemoteCollectionDriver to access a preexisting MongoDB Collection and trying to display the data using aldeed:tabular package.
I have the following code:
root/lib/hello.js
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
database = new MongoInternals.RemoteCollectionDriver("mongodb://localhost:27017/mydb");
idpool = new Mongo.Collection("idpool", {_driver:database});
Meteor.publish('idpool', function () {
return idpool.find();
});
});
}
Notice above I declare the collection. To use Tabular I need to declare this in the common code, not server-side code…continuing on in the same file I have.
TabularTables = {};
Meteor.isClient && Template.registerHelper('TabularTables', TabularTables);
TabularTables.idpool = new Tabular.Table({
name: "idpool",
collection: idpool,
columns: [
{data: "_id", title: "id"},
{data:"created", title: "created"}
]
});
books = new Mongo.Collection("books");
Meteor.isClient && Template.registerHelper('TabularTables', TabularTables);
TabularTables.books = new Tabular.Table({
name: "Books",
collection: books,
columns: [
{data: "_id", title: "id"}]
});
Now above is where I put the Tabular code in place. I setup two tables for testing. In the second table i declare the “books” collection in the common code. And the “books” table displays fine in the HTML page. However, I cannot re-declare the “idpool” collection since it would throw a “Error: A method named ‘/idpool/insert’ is already defined”
The most logical approach would be to declare the “idpool” collection in the common code, as I did with the “books” collection. However, this does not work since the “idpool” declaration is relying on this code which is not in scope of the common code
database = new MongoInternals.RemoteCollectionDriver("mongodb://localhost:27017/mydb");
Now one might think why not move the entire declaration down to common code (which is obviously bad to expose to the client, but just trying to make it work atm) but that is server-side specific code and causes the “idpool” collection not to get published.
TabularTables = {};
database = new MongoInternals.RemoteCollectionDriver("mongodb://localhost:27017/mydb");
idpool = new Mongo.Collection("idpool", {_driver:database});
Meteor.isClient && Template.registerHelper('TabularTables', TabularTables);
TabularTables.idpool = new Tabular.Table({
name: "idpool",
collection: idpool,
columns: [
{data: "_id", title: "id"},
{data:"created", title: "created"}
]
});
books = new Mongo.Collection("books");
Meteor.isClient && Template.registerHelper('TabularTables', TabularTables);
TabularTables.books = new Tabular.Table({
name: "Books",
collection: books,
columns: [
{data: "_id", title: "id"}]
});
I’m a bit perplexed. So I’m wondering what the correct way to do this is?