MongoDB
 SQL >> Database >  >> NoSQL >> MongoDB

Emulare populate() in Meteor con i collection helpers

collection helpers è molto probabilmente ciò che cerchi.

Uso di base:

Boards.helpers({ creator: function () { return Meteor.users.findOne(this.creatorId); }, category: function () { return Categories.findOne(this.categoryId); } }); 

Usarli in un template è semplice. Data la tua board:

{{#each boards}} <div> <h3>{{board_name}}</h3> <p>Created by</p>: {{ creator.username }} <p>Category</p>: {{ category.catname }} </div> {{/each}} 

Un ulteriore consiglio: abbina questo a publish-composite così che le relazioni vengano pubblicate in modo più gestibile.

Meteor.publishComposite('board', function (boardId) { check(boardId, String); return { find: function () { return Boards.find(boardId); }, children: [{ find: function (board) { return Meteor.users.find(board.creatorId); } }, { find: function (board) { return Categories.find(board.categoryId); } }] } });