原创

mongodbTemplate查询时返回指定字段

BasicDBObject dbObject = new BasicDBObject();

dbObject.put("id", "123");

dbObject.put("name", "haha");

//指定返回的字段

BasicDBObject fieldsObject = new BasicDBObject();

fieldsObject.put("id", true);

fieldsObject.put("name", true);

fieldsObject.put("age", true);

Query query = new BasicQuery(dbObject.toJson(), fieldsObject.toJson());

List<JavaEntity> list= mongoTemplate.find(query, JavaEntity.class, "collectionName");
好羞涩,内容都被你看完了。。
该篇文章的评论功能已被站长关闭