|
@@ -1,5 +1,7 @@
|
|
package com.ruixuan.common.utils.mongodb;
|
|
package com.ruixuan.common.utils.mongodb;
|
|
|
|
|
|
|
|
+import com.mongodb.client.MongoClient;
|
|
|
|
+import com.mongodb.client.internal.MongoClientImpl;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
@@ -19,6 +21,8 @@ public class MongoDBDemo {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private MongoTemplate mongoTemplate;
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
+ @Autowired
|
|
|
|
+ MongoClient mongoClient;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 新增:
|
|
* 新增:
|
|
@@ -38,7 +42,7 @@ public class MongoDBDemo {
|
|
|
|
|
|
public void saveAll() {
|
|
public void saveAll() {
|
|
List<PeopleDemo> list = new ArrayList();
|
|
List<PeopleDemo> list = new ArrayList();
|
|
- PeopleDemo people = new PeopleDemo("zhangsan", "zhangsan2", "张三", "13312345678");
|
|
|
|
|
|
+ PeopleDemo people = new PeopleDemo("zhangsan2", "zhangsan2", "张三2", "13312345678");
|
|
PeopleDemo people2 = new PeopleDemo("lisi", "lisi", "李四", "15512345678");
|
|
PeopleDemo people2 = new PeopleDemo("lisi", "lisi", "李四", "15512345678");
|
|
list.add(people);
|
|
list.add(people);
|
|
list.add(people2);
|
|
list.add(people2);
|
|
@@ -52,7 +56,7 @@ public class MongoDBDemo {
|
|
public void find() {
|
|
public void find() {
|
|
new PeopleDemo();
|
|
new PeopleDemo();
|
|
Criteria criteria = new Criteria();
|
|
Criteria criteria = new Criteria();
|
|
- criteria = Criteria.where("userId").is("zhangsan");
|
|
|
|
|
|
+ criteria = Criteria.where("userId").is("zhangsan2");
|
|
Query query = new Query(criteria);
|
|
Query query = new Query(criteria);
|
|
|
|
|
|
List<PeopleDemo> list = mongoTemplate.find(query, PeopleDemo.class);
|
|
List<PeopleDemo> list = mongoTemplate.find(query, PeopleDemo.class);
|
|
@@ -60,6 +64,9 @@ public class MongoDBDemo {
|
|
System.out.println("条件筛选结果:" + list);
|
|
System.out.println("条件筛选结果:" + list);
|
|
System.out.println("----All结果:" + all);
|
|
System.out.println("----All结果:" + all);
|
|
log.info("find ok");
|
|
log.info("find ok");
|
|
|
|
+
|
|
|
|
+ System.out.println("MongoDB线程池Pool信息:" + ((MongoClientImpl) mongoClient).getSettings().getConnectionPoolSettings());
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|