[英]Mongo Java-driver: recreation indexes after collection dropping
我有必要從mongo集合中刪除所有數據。 刪除collection的速度比collection.remove(new BasicDBObject())
更快。 但是它也刪除了索引定義。 因此,我想在刪除集合后恢復索引定義。
總的來說,我有以下計划:
對我來說,問題是應檢索/傳遞索引重新創建的確切值。 例如,將對所有類型的索引執行以下正確工作:
List<DBObject> storedDefinitions = coll.getIndexInfo();
coll.drop();
for (DBObject storedDefinition : storedDefinitions) {
coll.createIndex(storedDefinition.get("key"));
}
如果沒有-實現目標的最佳方法是什么?
謝謝你的幫助!
你近了 您將需要讀取檢索到的索引的索引選項,然后使用該方法的createIndex(DBObject key,DBObject options)版本將其應用於新創建的索引。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.