title: Mongodb inner join in java spring using AggregationOperation :Error [The 'cursor' option is required, except for aggregate with the explain argument]
body: <p>I am excecuting following mongodb query  I am new to mongo db ,please tell me what i am doing wrong</p>
  
  <pre><code>   db.entityCounter.aggregate([
     {
       $lookup:
         {
           from: "fields",
           localField: "code",
           foreignField: "fieldCode",
           as: "fieldsresult"
         }
    },{
        $match:{
            $and: [{
                "fieldsresult.isVisible":"1"
                },{"type":"field"
                    }]
            }
            }])
  </code></pre>
  
  <p>below is java spring code </p>
  
  <pre><code>  LookupOperation lookupOperation = LookupOperation.newLookup()
              .from("fields")
              .localField("code")
              .foreignField("fieldCode")
              .as("fieldsresult");
  
      AggregationOperation match1 = Aggregation.match(Criteria.where("fieldsresult.isVisible").is("1"));
  
     // AggregationOptions aggregationOptions = Aggregation.newAggregationOptions();
      DBObject ob=new BasicDBObject();
      ((BasicDBObject) ob).put("batchSize",10);
      Aggregation aggregation = Aggregation.newAggregation(lookupOperation,match1).withOptions(Aggregation.newAggregationOptions().cursor(ob).build());
  
  
  
  long val=0;
  try {
      AggregationResults&lt;EntityCounter&gt; result = mongoOperations.aggregate(aggregation, Fields.class, EntityCounter.class);
      // val= result.getMappedResults();
  }catch (Exception e){
      e.printStackTrace();
  
  }
  </code></pre>
  
  <p>but I am getting  below error </p>
  
  <blockquote>
    <p>org.springframework.dao.InvalidDataAccessApiUsageException: Command execution failed:  Error [The 'cursor' option is required, except for aggregate with the explain argument], Command = { "aggregate" : "entityCounter" , "pipeline" : [ { "$match" : { "fieldsresult.isVisible" : "1"}} , { "$lookup" : { "from" : "fields" , "localField" : "code" , "foreignField" : "fieldCode" , "as" : "fieldsresult"}}]}; nested exception is com.mongodb.MongoCommandException: Command failed with error 9: 'The 'cursor' option is required, except for aggregate with the explain argument' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "The 'cursor' option is required, except for aggregate with the explain argument", "code" : 9, "codeName" : "FailedToParse" }</p>
  </blockquote>