Trần Kim Dự
Trần Kim Dự

Reputation: 6102

Meteor: best practice for creating database

In my Meteor application, in lib folder (the folder that all code will be executed first). I create a file name database.js which contains:

tblUser = new Mongo.collection("Users");
tblComment = new Mongo.collection("Comments");

By use this way, I think:

  1. tblUser and tblComment is global variable, so can access like we get a table from database.
  2. If this is first run, Users collection, Comments collection, ... will be created automatically. If not, I can get already created tblUser and tblComment document from database.

Are 2 above assumptions right ? If wrong, please correct me.

Thanks :)

Upvotes: 0

Views: 178

Answers (2)

JuanCrg90
JuanCrg90

Reputation: 1016

  1. A meteor project have the autopublish and insecure packages. So, you should remove it and use a publish - suscribe policy in your application.

  2. Remember, mongodb is no-sql, the collections don't will be created until you do the first insert.

Upvotes: 1

sdooo
sdooo

Reputation: 1881

Your assumptions are correct, you just gotta remember about good pub/sub code.

Although, if you still got autopublish package then yes, your Collections are something like tables that hold same data as server, you just gotta fetch() them like tblUser.find().fetch()

Upvotes: 2

Related Questions