我正在尝试从数据库中删除所有文档,但我想保留视图。所以我试过
//First, get all DesignDocument for the current database
List<DesignDocument> dbDesigns = cloudant.getDesignDocumentManager().list();
//Now, we delete the database
cloudantClient.deleteDB(_DatabaseName);
//now we create the database again
cloudant = cloudantClient.database(_DatabaseName, true);
//finally, try to add the DesignDocuments back
if (dbDesigns != null && dbDesigns.size() > 0) {
for (DesignDocument dDoc : dbDesigns) {
Response response = cloudant.getDesignDocumentManager().put(dDoc);
System.out.println(response);
}
}
但我在
时遇到错误Response response = cloudant.getDesignDocumentManager().put(dDoc);
java.lang.IllegalArgumentException: rev should be null
at com.cloudant.client.org.lightcouch.internal.CouchDbUtil.assertNull(CouchDbUtil.java:72)
at com.cloudant.client.org.lightcouch.CouchDbClient.put(CouchDbClient.java:410)
at com.cloudant.client.org.lightcouch.CouchDbClient.put(CouchDbClient.java:394)
at com.cloudant.client.org.lightcouch.CouchDatabaseBase.save(CouchDatabaseBase.java:196)
at com.cloudant.client.api.Database.save(Database.java:710)
at com.cloudant.client.api.DesignDocumentManager.put(DesignDocumentManager.java:122)
还有其他方法来保存视图吗?
答案 0 :(得分:1)
我怀疑是因为文档修订属性(_rev
)在dDoc
中设置而引发错误。但是,由于在数据库中找不到具有匹配id的文档,put
方法会引发错误。在调用put
setRevision
方法将修订版设置为null
dDoc.setRevision(null);
Response response = cloudant.getDesignDocumentManager().put(dDoc);