Skip to content

Instantly share code, notes, and snippets.

function unixTimestampSeconds() {
return Math.floor(Date.now() / 1000);
}
function messageData () {
var fiveHoursAgo = unixTimestampSeconds() - 5 * 60 * 60;
return Messages.find({unixTimestamp: {$gte: fiveHoursAgo}});
}
function userData () {
return Meteor.users.find({}, {fields: {'status.online': 1, username: 1}});
}
if (Meteor.isServer) {
// In `meteor shell`:
> new Mongo.Collection("messages")
Error: A method named '/messages/insert' is already defined
at packages/ddp/livedata_server.js:1461:1
at Function._.each._.forEach (packages/underscore/underscore.js:113:1)
at [object Object]._.extend.methods (packages/ddp/livedata_server.js:1459:1)
at [object Object].Mongo.Collection._defineMutationMethods (packages/mongo/collection.js:904:1)
at new Mongo.Collection (packages/mongo/collection.js:209:1)
at [object Object].ns.Collection (packages/lai:collection-extensions/collection-extensions.js:71:1)
> Rooms.findOne({name: 'linux'})
{ _id: 'QrBSYEy4PQL9e6svb',
name: 'linux',
unixTimestamp: 1428397795,
joinedUsers: [ 'JNkrbokz2393fLDjg' ] }
> Rooms.findOne({name: "doesn't exist"})
> x = Rooms.findOne({name: "doesn't exist"})
> x
>
Template.body.helpers({
messages: function () {
return Messages.find({room: $('#joined-rooms').val()});
}
});
<template name="joinedRoomsList">
<select id="joined-rooms">
{{#each joinedRooms}}
<option>{{name}}</option>
{{/each}}
</select>
</template>
if (Meteor.isServer) {
function onlineUsers () {
return function () {
return Meteor.users.find({'status.online': true}, {fields: {'status.online': 1, username: 1}});
}
}
Meteor.publish("onlineUsers", onlineUsers);
}
<section id="users">
{{#with room}}
{{#each joinedUsers}}
<div class="user">{{this}}</div>
{{/each}
{{/each}}
</section>
@brlafreniere
brlafreniere / gist:23b94c2b2dd67b94f513
Last active August 29, 2015 14:18
The {{#each}} block doesn't appear to be rendering. The modal does display, I can see the modal, and inspecting it in the Chrome inspector I can see the HTML, just nothing in between the <table> elements.
<template name="roomsList">
<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Rooms List</h4>
</div>
<div class="modal-body">
<table>
{{#each rooms}}
'click #join-room': function (event) {
bootbox.prompt("Enter the name of the room you want to join.", function(roomName) {
if (roomName !== null) {
joinRoom(roomName);
$('#joined-rooms').val(roomName); // this is the line that isn't working.
}
});
},