如何使用Java为Cloudant DB中的文档添加特定于用户的唯一id
我在如何使用Java为Cloudant DB中的文档添加特定于用户的唯一id,java,cloudant,Java,Cloudant,我在CloudantDB中有一个文档,如下所示: { "_id": "9567e004dc1f1063f4e5cfa9471f5f6b", "_rev": "1-77c3cab7cc5ba63277843b4dafc6af42", "DocumentUri": "http://www.ibm.com/common/ssi/cgi-bin/ssialias?htmlfid=515-125EN&infotype=AN&subtype=CA&appname=skmw
Cloudant
DB中有一个文档,如下所示:
{
"_id": "9567e004dc1f1063f4e5cfa9471f5f6b",
"_rev": "1-77c3cab7cc5ba63277843b4dafc6af42",
"DocumentUri": "http://www.ibm.com/common/ssi/cgi-bin/ssialias?htmlfid=515-125EN&infotype=AN&subtype=CA&appname=skmwww",
"username": "SKM",
"DocumentDetails": {
"ContentType": "text/plain",
"Language": "en",
"Content": "515-125 Price Change(s):Price change: DOORS Family AU price change Today,
}
\u id
值存储在我的应用程序的属性文件中。我需要知道如何从属性文件中获取id名称,然后使用Java将其分配给Cloudant DB中的文档id。您可以通过阅读了解如何读取属性文件
然后,您可以创建一个Java对象,将_id作为成员变量,然后将该对象插入到db中——Cloudant中的_id属性将自动使用您在对象中设置的_id
public class Reservation {
public String _id;
public String name;
public Reservation(){
_id = "";
name = "";
}
}
当你准备好保存它的时候。这将使用客户端
//Cloudant Connection
CloudantConnect connectParams = new CloudantConnect();
CloudantClient client = new CloudantClient(cloudantUrl,cloudantUsername, cloudantPassword);
Database db = client.database("myDatabase", false);
Reservation reservation = new Reservation();
Response dbResponse = db.save(reservation);
System.out.print(dbResponse.toString());