title: Spring Boot java with Mongodb
body: <pre><code>package com.javatechie.spring.mongo.api.resource;
  
  import java.util.List;
  import java.util.Optional;
  
  import org.bson.Document;
  import org.bson.json.JsonReader;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.QualifierAnnotationAutowireCandidateResolver;
  import org.springframework.data.mongodb.core.MongoTemplate;
  import org.springframework.web.bind.annotation.DeleteMapping;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RestController;
  
  import com.javatechie.spring.mongo.api.model.Book;
  import com.javatechie.spring.mongo.api.repository.BookRepository;
  
  @RestController
  public class BookController {
  
      @Autowired
      private BookRepository repository;
  
      @Autowired
      private  MongoTemplate mongoTemplate;
  
      @PostMapping(&quot;/addBook&quot;)
      public String saveBook(@RequestBody Book book) {
          repository.save(book);
          return &quot;Added book with id : &quot; + book.getId();
      }
  
     @GetMapping(&quot;/findAllBooks&quot;)
     public List&lt;Book&gt; getBooks() {
         String jsonCommand = &quot;{ aggregate: 'Book', pipeline: [ { $project: { _id: 0, 'bookName': 1 
      } } ], cursor: { } }&quot;;
         Document resultDoc = mongoTemplate.executeCommand(jsonCommand);
         System.out.println(resultDoc);
         return repository.findAll();
     }
  </code></pre>
  <p>I am successfully able to print a specific field on the console using this<br />
  String jsonCommand = &quot;{ aggregate: 'Book', pipeline: [ { $project: { _id: 0, 'bookName': 1 } } ], cursor: { } }&quot;;<br />
  but I want to print specific data for example in my bookName field there are many books so I want to print only those which are Python currently it is printing all bookName.</p>
  <p>Kindly help me out here iam stuck</p>