mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-13 12:15:15 +00:00
perf[mongo]: 增加新的方法
This commit is contained in:
1 parent
20dd452697
commit
e449f326d6
2 files changed
+20
-3
No files matched your search
@@ -78,10 +78,20 @@ public abstract class MongoIdUtils {
|
||||
* @param documentName 档id
|
||||
*/
|
||||
public static void resetIncrementIdFromMongoDefault(String documentName) {
|
||||
var collection = OrmContext.getOrmManager().getCollection(COLLECTION_NAME);
|
||||
setIncrementIdFromMongo(0L, COLLECTION_NAME, documentName);
|
||||
}
|
||||
|
||||
collection.findOneAndUpdate(Filters.eq("_id", documentName)
|
||||
, new Document("$set", new Document(COUNT, 0L)));
|
||||
public static void setIncrementIdFromMongo(long value, Class<?> clazz) {
|
||||
setIncrementIdFromMongo(value, COLLECTION_NAME, StringUtils.uncapitalize(clazz.getSimpleName()));
|
||||
}
|
||||
|
||||
public static void setIncrementIdFromMongo(long value, String documentName) {
|
||||
setIncrementIdFromMongo(value, COLLECTION_NAME, documentName);
|
||||
}
|
||||
|
||||
public static void setIncrementIdFromMongo(long value, String collectionName, String documentName) {
|
||||
var collection = OrmContext.getOrmManager().getCollection(collectionName);
|
||||
collection.findOneAndUpdate(Filters.eq("_id", documentName), new Document("$set", new Document(COUNT, value)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -78,4 +78,11 @@ public class MongoIdUtilsTest {
|
||||
MongoIdUtils.resetIncrementIdFromMongoDefault("myDocument");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void set() {
|
||||
var context = new ClassPathXmlApplicationContext("application.xml");
|
||||
var id = MongoIdUtils.getIncrementIdFromMongoDefault("myDocument");
|
||||
System.out.println(id);
|
||||
MongoIdUtils.setIncrementIdFromMongo(100, "myDocument");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user