Checking if a field in any user document exists


#1

How can I check if a field exists in any users fields?

For now im setting the following on the client during a signin flow:

Meteor.users.update(Meteor.user()._id, {$set: {'profile.website': 'somecustomsite.com'}}, func(){}

I just need to do a simple check on the server if somecustomsite.com exists in any users profile.website field. How can I do that?


#2

Meteor.users.find({'profile.website': 'somecustomsite.com'})


// also you can do text search since it may be case
// sensitive. 

Meteor.users.find({'profile.website': {$text: 'somecustomsite.com'}})

Also {fieldName: {$exists: true/false }) if you want to get any empty/filled users to see if unset on any. 

See mongodb $text operator and regex options docs