In command prompt I enter the following:
db.products.insert( { item: "card", qty: 15 } )
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".
I am currently using MongoOperations in java but I do not know how to get only one value from MongoDB.
Pojo
@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
Long Shot Attempt
@Autowired
MongoOperations mongoOperations;
@PostConstruct
public List<SomeModel> getList() {
List<SomeModel> 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);
With command prompt
I am able to get a value by using the following command:
db.products.find({}, {qty:0, _id:0})
//output ("item": "card")
I want to achieve the following:
db.products.find({}, {item})
//output should be "card".
is it possible to do what I just did above?