mongodb 根據_id 查詢記錄:
public Price queryPriceById(String id) throws Exception { return mongoTemplate.findById(new ObjectId(id), Price.class, PRICE_COLLECTION); }
根據集合中的某個字段查詢:
public Price queryPriceByName(String name) throws Exception { Price price = null; price = mongoTemplate.findOne(new Query(Criteria.where("name").is(name)), Price.class, PRICE_COLLECTION); return price; }