node.js - Mongoose. Use a constant in $or -


i'm building query , include access control:

  var q = { $and:     [       { $or: [           isadmin,    // use have access resources?                       // pattern doesn't appear work           { ispublic: true },           { createdby: userid }         ]       },       query     ]   };   resource.find(q).sort('-createdat').limit(10)... 

isadmin can true or false. if false, i'd other tests. query rest of query.

it's not working in mongoose 4.0.4. suggestions?

ok, found 2 ways this. best way not include $or when isadmin. kind of obvious really.

function findnewestresources(query, callback) {   if (!isadmin) {     query = { $and:       [         { $or: [             { ispublic: true },             { createdby: userid }           ]         },         query       ]     };   }   resource.find(query).sort('-createdat').limit(10) 

an alternate way use $where, table-scan, that's no good. $where worked on 2.6.10, not on 2.6.9.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -