javascript - Select documents of a collection depending on user roles -


i need documents of collection has specific value field (section) - depends on user role - or userid field user.

so i'm trying check if user in role , put query:

var sectionone = roles.userisinrole(meteor.userid(), ['something']) ? { section: 'cars' } : undefined; var sectionsecond = roles.userisinrole(meteor.userid(), ['anything']) ? { section: 'vegetables' } : undefined; var sectionthird = roles.userisinrole(meteor.userid(), ['else']) ? { section: 'countries' } : undefined;  var count = collection.find(     {         $or: [             sectionone,             sectionsecond,             sectionthird,             { user: userid },         ],         read: {              $nin: [ userid ]          }     } ).count();  console.log(count); 

what correct way that?

for better understanding here example of i'm trying do:

example

if user has roles something , else, query should this:

var count = collection.find(     {         $or: [             { section: 'cars' },             { section: 'countries' },             { user: userid },         ],         read: {              $nin: [ userid ]          }     } ).count(); 

so documents has cars or countries or userid , userid not in read-array selected that, right?

update

i think question not precise enough. let me explain bit better:

i want docs of collection user: userid - if there docs matches this.

additional (!) need docs matches section: 'cars' if user has role something. in case there more results.

if user has role anything want results of section: 'vegetables' , add them result. of these things not depending on each other.

excluding last thing read: { $nin: [ userid ] }: should needed thing every single match described above.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -