View our GitHub

Please visit sails-docs on GitHub to view documentation on your mobile device.

Edit Page


Default “where” criteria for user with blueprint find and update actions.

Note: Before using req.options.where, confirm that it exists and create it if necessary.


To default to finding only records where userId matches the logged-in user’s id:

// In config/policies/filterByUser.js
module.exports = function filterByUser (req, res, next) {

  if (req.session.user) {

    // Use existing req.options.where, or initialize it to an empty object
    req.options.where = req.options.where || {};

    // Set the default `userId` for "find" and "update" blueprints
    req.options.where.userId =;


  return next();


Then apply this policy to the desired blueprint actions.

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.


We wrote a book!

Get early access to the book
with promotion code: mcneildoc

Get the Book