Last active
August 29, 2015 14:22
-
-
Save gentunian/c0a3d8a755c86636a93d to your computer and use it in GitHub Desktop.
collection.findOne() bug?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<title>test-findOne</title> | |
</head> | |
<body> | |
{{> testTemplate}} | |
</body> | |
<template name="testTemplate"> | |
<p>{{testFindOneHelper}}</p> | |
<p>{{testFindHelper}}</p> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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