title: Spring-data-mongodb intercept query and inject predicate or specification
body: <p>Environment:</p>
  
  <p>spring-data-mongo: <code>1.7.0.RC1</code>
  mongo-java-driver: <code>3.2.2</code></p>
  
  <p>Document:</p>
  
  <pre><code>@Document(collection = "products")
  public class Product  {
  
      @Id
      private String sid;
  
      private String name;
  
      private Long vendor;
  
      (...)
  }
  </code></pre>
  
  <p>Repository:</p>
  
  <pre><code>public interface ProductRepository extends MongoRepository&lt;Product, String&gt; {
  
      Product findByName(String productName);
  
  }
  </code></pre>
  
  <p>My goal is to intercept any query performed on the Product collection and add a predicate or a specification without modifying the repository or the need to implement the method findByNameAndBelongsToVendorList.</p>
  
  <p>I need this interceptor or aspectJ because I have multiple methods like:</p>
  
  <pre><code>Page&lt;Product&gt; findAll(Pageable page);
  
  List&lt;Product&gt; findByCategory(String category, Pageable pageRequest);
  
  (...)
  </code></pre>
  
  <p><strong>Goal</strong></p>
  
  <pre><code>findByName // perform a filter by name (explicit) 
             // and a filter by vendor (injected via inteceptor or aspecJ)
  </code></pre>
  
  <p><strong>Avoid doing this</strong></p>
  
  <pre><code>@Repository
  public class ProductRepositoryCustomImpl implements ProductRepositoryCustom {
  
      @Autowired
      private MongoTemplate template;
  
      public Product findByNameAndBelongsToVendorList(String name, List&lt;Long&gt; vendors, Pageable pageRequest) {
  
          Criteria criteriaVendor = Criteria.where("vendors").in(vendors);
          Query query = new Query(criteriaVendor);
          query.with(pageRequest);
  
          return template.findOne(query, Product.class);
      }
  }
  </code></pre>