Mongodb 非映射查询写法 (java)
//1.获取集合对象
MongoCollection<Document> collection = niuTemplate.getCollection("db_xxx");
//2.创建用于查询的BSON对象
Bson bson = eq("filed", "value");
//3.利用bson条件查询结果
FindIterable<Document> documents = collection.find(bson);
//4.将结果拼接成json数组
StringBuilder sb = new StringBuilder();
sb.append("[");
for(Document document : documents) {
sb.append(document.toJson() + ",\n");
}
sb.append("]");
System.out.println("sb:" + sb);
转载
https://blog.csdn.net/weixin_42067697/article/details/131654333

浙公网安备 33010602011771号