meteor

How do you call a Meteor template helper from the console or other JS code?

∥☆過路亽.° 提交于 2019-12-17 19:47:00
问题 I've defined a template helper in Meteor, say Template.postsList.helpers({ filteredPosts: function getPosts() { return Posts.find(...); } }); How can I debug that template helper from the console, and how can I reuse it from other code in the app? 回答1: Wanting to call the helper from elsewhere in the app suggests that you should factor it out in a function. To quickly debug the helper, evaluate this in the client console: Template.postsList.__helpers.get('filteredPosts')(...parameters); There

Are “group by” aggregation queries possible in Meteor, yet?

别来无恙 提交于 2019-12-17 19:42:42
问题 Is a Mongo-style db.collection.group(...) query possible in Meteor, yet? I was hoping i could run something like this on the server (coffeescript): Meteor.publish "top10", -> Records.group key: {name:true} reduce: (obj, agg) -> agg.count++ initial: {count:0} 回答1: Actually not yet. Meteor uses node-mongo-native to do CURD in the server-side, whilst minimongo in the client-side. And Meteor keeps same API in the both side. The document says - In this release, Minimongo has some limitations: ...

Using Iron Router to waitOn subscription that's dependent on data from a doc that will come from another subscription

微笑、不失礼 提交于 2019-12-17 19:39:53
问题 I'm having trouble configuring the waitOn portion of a route where one of the subscription's parameters is determined by the value from a doc that comes from a different subscription. The collections in play are Candidates and Interviews. An interview will have one and only one candidate. Here's some sample data: candidate = { _id: 1 firstName: 'Some', lastName: 'Developer' //other props }; interview = { _id: 1, candidateId: 1 //other props }; The route is configured as follows. this.route(

“group by” queries on meteor collection

≡放荡痞女 提交于 2019-12-17 18:44:23
问题 My data mongoDB : >db.CUSTOMER.find() {"Name": "A", "CreatedDate": "Wed Jan 29 2014"} {"Name": "B", "CreatedDate": "Fri Jan 31 2014"} {"Name": "C", "CreatedDate": "Sat Feb 01 2014"} {"Name": "D", "CreatedDate": "Sat Feb 01 2014"} In meteor: Customer = new Meteor.Collection("CUSTOMER"); I'm trying to group them by date (Mon, Tues, Wed, ...) in meteor collection along with the total of the data. It should be something like this: {"Date": "Wed Jan 29 2014", "Total" 1} {"Date": "Fri Jan 31 2014",

Does Meteor have a distinct query for collections?

一世执手 提交于 2019-12-17 18:43:34
问题 I'd like to return distinct fields in my collection. I know these are the docs for mongo operators, but I'm not familiar enough with the query language to know if this is possible? Meteor.publish("distinctCollection", function() { return Collection.find({ ... }, fields: { "myField": 1 }); }); 回答1: Collection.find({}).distinct('myField', true); To use, put the following in [project]/client/lib/a.js: LocalCollection.Cursor.prototype.distinct = function (key,random) { var self = this; if (self

Does Meteor have a distinct query for collections?

余生颓废 提交于 2019-12-17 18:43:04
问题 I'd like to return distinct fields in my collection. I know these are the docs for mongo operators, but I'm not familiar enough with the query language to know if this is possible? Meteor.publish("distinctCollection", function() { return Collection.find({ ... }, fields: { "myField": 1 }); }); 回答1: Collection.find({}).distinct('myField', true); To use, put the following in [project]/client/lib/a.js: LocalCollection.Cursor.prototype.distinct = function (key,random) { var self = this; if (self

How to add CORS headers to a Meteor app?

我的梦境 提交于 2019-12-17 18:29:00
问题 How it is possible to add Access-Control-Allow-Origin: * header to all responses (in particular, I am interested for static files under /public/ ) in Meteor? I would need this so that external web apps can access data provides by my Meteor app. More information about enabling CORS is here. 回答1: Here is a little snippet I wrote. You can use as an example in how to access meteor's core connect and modify headers, also a pretty good drop-in for every meteor project: /** * HTTP Header Security *

Meteor subscribe to a count

大城市里の小女人 提交于 2019-12-17 18:27:13
问题 Is there any way to subscribe to a count in meteor. I want to publish Articles.find().count() rather than publish Articles.find(). Ideally this should assign the count to a reactive Session that would change when the count changes. 回答1: I have following code to publish my counters Meteor.publishCounter = (params) -> count = 0 init = true id = Random.id() pub = params.handle collection = params.collection handle = collection.find(params.filter, params.options).observeChanges added: => count++

Meteor Handlebars: How to access a plain array?

China☆狼群 提交于 2019-12-17 18:17:23
问题 var plain_array = [1, 2, 3, 4, 5, 6, 7] How can I show all elements in Meteor Handlebars? {{#each plain_array}} # What to put here to get the elements? {{/each}} (This question is similar: handlebars: how to access an array? but not the same as the other question presumes an array of objects.) 回答1: From Handlebars documentation. {{#each people}} <li>{{this}}</li> {{/each}} 来源: https://stackoverflow.com/questions/21234947/meteor-handlebars-how-to-access-a-plain-array

How do I add console.log() JavaScript logic inside of a Handlebars template?

怎甘沉沦 提交于 2019-12-17 17:54:40
问题 I'm in the process of building a new Meteor app and I can't figure out how to add JavaScript logic with Handlebars to run a console.log() before my each loop. In backbone I would just do, <% console.log(data); %> to test that the data was being passed in. I'm not sure how to do this with Meteor and Handlebars and I couldn't find the solution on their site. 回答1: Create a Handlebars helper in one of the client-loaded JavaScript files in your project: Template.registerHelper("log", function