mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-19 03:26:59 +00:00
perf[orm]: 新增重置mongodb的uuid的重置方法
This commit is contained in:
@@ -69,6 +69,24 @@ public abstract class MongoIdUtils {
|
||||
return getIncrementIdFromMongo(COLLECTION_NAME, StringUtils.uncapitalize(clazz.getSimpleName()));
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 重置documentName的数值,重置为0
|
||||
*
|
||||
* @param documentName 档id
|
||||
*/
|
||||
public static void resetIncrementIdFromMongoDefault(String documentName) {
|
||||
var collection = OrmContext.getOrmManager().getCollection(COLLECTION_NAME);
|
||||
|
||||
collection.findOneAndUpdate(Filters.eq("_id", documentName)
|
||||
, new Document("$set", new Document(COUNT, 0L)));
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 获取最大的id
|
||||
*
|
||||
|
||||
@@ -70,4 +70,12 @@ public class MongoIdUtilsTest {
|
||||
ThreadUtils.sleep(Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reset() {
|
||||
var context = new ClassPathXmlApplicationContext("application.xml");
|
||||
var id = MongoIdUtils.getIncrementIdFromMongoDefault("myDocument");
|
||||
System.out.println(id);
|
||||
MongoIdUtils.resetIncrementIdFromMongoDefault("myDocument");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user