cxg222
October 26, 2017, 2:49am
1
Q: how to query a property of an object of a collection in meteor?
eg:
I have the following users collection:
{
_id: 'QwkSmTCZiw5KDx3L6', // Meteor.userId()
username: 'cool_kid_13', // Unique name
emails: [
{ address: 'cool@example.com', verified: true },
],
createdAt: new Date('Wed Aug 21 2013 15:16:52 GMT-0700 (PDT)'),
profile: {
name: 'Joe Schmoe'
},
}
when i query it from the server side using the following code:
Meteor.users.find({profile.name:'Joe Schmoe'});
the compiler throws typo error.
when i query it as the following code, it simply returns nothing.
Meteor.users.find({'profile.name':'Joe Schmoe'});
BUT the mongo shell the following code works
db.users.find({'profile.name':'Joe Schmoe'});
ANY IDEA?
hluz
October 26, 2017, 3:16am
2
cxg222:
when i query it as the following code, it simply returns nothing.
Meteor.users.find({‘profile.name’:‘Joe Schmoe’});
Is that on the client or on the server?
cxg222:
when i query it as the following code, it simply returns nothing.
Meteor.users.find({‘profile.name’:‘Joe Schmoe’});
the quotes around profile.name are important, but the command returns a cursor. Have you tried the following on the server?
Meteor.users.findOne({'profile.name':'Joe Schmoe'});
leosco
October 26, 2017, 8:12pm
4
Collection.find()
doesn’t return the results, it returns a reactive cursor. To get the actual results, you’ve gotta use find().fetch()
.
hluz
October 27, 2017, 3:43am
6
Well, it then returns something: a cursor (like others said). In the client, if the cursor itself is being used in a template inside an #each helper - {{#each cursorname}} - then Blaze will iterate the cursor for you. In the server, it is up to you to iterate the cursor.