Why would this not work?:
On both the client and server:
AllUsers = new Meteor.Collection('allUsers');
On the server only:
Meteor.publish('allUsers', function() {
return Meteor.users.find();
});
On the client only:
Deps.autorun(function(){
Meteor.subscribe("allUsers");
});
After I start up this app, AllUsers.find().count()
is 0 but doing db.users.find().count()
in the terminal gives the correct number (3). Even after I add a new user in the browser (using the standard ui-accounts
package form), which should certainly cause the users collection to change, I still have no documents in my AllUsers
collection. I'm beating my head against the wall trying to solve this!
Meteor collections defined on the server have a 1:1 relationship with collections in the database. You don't have a collection in the DB called 'allusers'
, so that definition doesn't make sense. It seems like you are confusing the notion of a database collection and a published result set.
When you add the accounts package to your project, meteor defines the Meteor.users
collection for you on both the client and the server, so you don't need to do that again. Your code looks fine - just remove the new Meteor.Collection
and access the users via Meteor.users.find
.
Meteor.users
is created by the accounts
packagedb.users
. You can make this collection look like the others you define by doing something like Users = Meteor.users
, and later calling Users.find()
instead of Meteor.users.find()
.new Meteor.Collection('rooms')
'rooms'
is the name of the collection in the database (db.rooms
). Documents can be published from the server to the client.new Meteor.Collection('userCount')
'userCount'
does not correspond to the name of a DB collection, but instead is simply an identifier agreed upon by the client and server.new Meteor.Collection(null)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With