title: How to get a specific value in Mongodb using Java?
body: <p>In command prompt I enter the following:</p>
  
  <pre><code>db.products.insert( { item: "card", qty: 15 } )
  </code></pre>
  
  <p>I wanted to know how would I be able to get the item value from java.
  I want to create a variable called item and it would know the value of it which is "card".</p>
  
  <p>I am currently using MongoOperations in java but I do not know how to get only one value from MongoDB.</p>
  
  <p><strong>Pojo</strong></p>
  
  <pre><code>@Document(collection="products") 
  public class ValueServerModel{
  
      @Id
      private String id;
  
      String item;
  
      int qty;
  
  
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public String getItem() {
          return item;
      }
  
      public void setItem(String item) {
          this.item = item;
      }
  
      public int getQty() {
          return qty;
      }
  
      public void setQty(int qty) {
          this.qty = qty;
      }
  
      public Product(String item, int qty) {
          //super();
          this.item = item;
          this.qty = qty;
      }
  
      @Override
      public String toString() {
          return "Product [id=" + id + ", item=" + item + ", qty=" + Integer.toString(qty) + "]";
      }
  
  }
  
  //provided by suwal
  </code></pre>
  
  <p><strong>Long Shot Attempt</strong></p>
  
  <pre><code>@Autowired
  MongoOperations mongoOperations;
  
  @PostConstruct
  public List&lt;SomeModel&gt; getList() {
  List&lt;SomeModel&gt; pmLst = mongoOperations.findAll(ServerModel.class);
  //code above works I get a list of values based on mongo db
  
  //attempting to retrieve one value, (stuck)
  String value = mongoOperations.find("test", ValueServerModel.class);
  </code></pre>
  
  <p><strong>With command prompt</strong></p>
  
  <p>I am able to get a value by using the following command:</p>
  
  <pre><code>db.products.find({}, {qty:0, _id:0})
  //output ("item": "card")
  </code></pre>
  
  <p>I want to achieve the following:</p>
  
  <pre><code>db.products.find({}, {item})
  //output should be "card".
  </code></pre>
  
  <p>is it possible to do what I just did above?</p>