Skip to content

Instantly share code, notes, and snippets.

@gentunian
Last active August 29, 2015 14:22
Show Gist options
  • Save gentunian/c0a3d8a755c86636a93d to your computer and use it in GitHub Desktop.
Save gentunian/c0a3d8a755c86636a93d to your computer and use it in GitHub Desktop.
collection.findOne() bug?
meteor create testFindOne
cd testFindOne
meteor mongo
# insert some data
db.users.insert({id:1, profilePicture: 'test1.png'});
db.users.insert({id:2, profilePicture: 'test1.png'});
# exit mongo
meteor
open: http://127.0.0.1:3000
press F12 or whatever you use to see JS console.
You will get something like:
[testFindOneHelper]Wed Jun 03 2015 19:49:15 GMT-0300 (ART)
[testFindOneHelper]undefined
[testFindHelper]Wed Jun 03 2015 19:49:15 GMT-0300 (ART)
[testFindHelper][object Object]
[testFindOneHelper]Wed Jun 03 2015 19:49:15 GMT-0300 (ART)
[testFindOneHelper][object Object]
<head>
<title>test-findOne</title>
</head>
<body>
{{> testTemplate}}
</body>
<template name="testTemplate">
<p>{{testFindOneHelper}}</p>
<p>{{testFindHelper}}</p>
</template>
Users = new Mongo.Collection('users');
if (Meteor.isClient) {
Template.testTemplate.helpers({
testFindOneHelper: function () {
console.log('[testFindOneHelper]' +new Date());
var u = Users.findOne({});
console.log('[testFindOneHelper]' +u);
}
});
Template.testTemplate.helpers({
testFindHelper: function () {
console.log('[testFindHelper]' + new Date());
var u = Users.find({});
console.log('[testFindHelper]' +u);
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment