user5030225
user5030225

Reputation:

Meteor: How do I check if a collection exists

I am using accounts entry, and as you may know, it doesn't allow taking you to separate pages on signup and signin.

So, what I want to do is check if a field called under profile called "avatar" exists. I just want a true or false answer (or null, -1, etc).

How can I do this?

Upvotes: 0

Views: 826

Answers (2)

David Weldon
David Weldon

Reputation: 64312

Here's a function that will return a boolean indicating if the avatar field exists in the current user's profile:

var hasAvatar = function() {
  var user = Meteor.user();
  return user && user.profile && user.profile.avatar;
};

Upvotes: 2

hafiz ali
hafiz ali

Reputation: 1446

If its a user collection where all the user data is stored, you can simply do Meteor.user() in the browser console and get the data.

If you have stored in some mongo collection than all you got to do is CollectionName.find().fetch()

Also if you have avatar field in profile of user collection than you can simple do Meteor.user().profile.avatar It will show an object if it exist. :)

try and let me know :)

Upvotes: 0

Related Questions