什么是正确的hello world程序使用c#, couchdb和LoveSeat

本文关键字:couchdb LoveSeat 程序 world hello 什么 | 更新日期: 2023-09-27 17:50:37

我正在尝试在couchdb数据库中存储一个简单的c# hello world。

我正在使用LoveSeat(但如果有帮助,请随意建议另一个客户端),并创建了这个简单的代码:

static void Main(string[] args)
{
    var cl = new CouchClient("myserver", 5984, null, null);
    var db = cl.GetDatabase("mydb");
    var newDoc = db.CreateDocument(@"{
""Test"":""ValueTest""
}"
    );
    var newDoc2 = db.SaveDocument(newDoc);
}

实际创建文档:

{
   "_id": "805656b6113d30a5387230a669000bb6",
   "_rev": "1-44c5768a2fa004c6a43899687c283517",
   "Test": "ValueTest"
}

但是当我查看结果newDoc2时,我看到:

{
  "error": "file_exists",
  "reason": "The database could not be created, the file already exists."
}

我做错了什么吗?

thx

什么是正确的hello world程序使用c#, couchdb和LoveSeat

CreateDocument实际将新文档添加到couchdb。之后就不需要调用SaveDocument了。SaveDocument用于在对文档进行更改后更新文档。我不确定,但似乎在尚未更新的文档上调用SaveDocument会给你这个错误。如果您对文档进行更改,然后调用SaveDocument,我希望它能正常工作。

我阅读了LoveSeat的源代码:

public Document SaveDocument(Document document)
{
    if (document.Rev == null)
        return CreateDocument(document);
    var resp = GetRequest(databaseBaseUri + "/" + document.Id + "?rev=" + document.Rev).Put().Form().Data(document).GetResponse();
    var jobj = resp.GetJObject();
    //TODO: Change this so it simply alters the revision on the document past in so that there isn't an additional request.
    return GetDocument(document.Id);
}

所以如果document.Rev==null, SaveDocument与CreatDocument相同
如果document.Rev!=null, SaveDocument实际上是"UpdateDocument"。

你的代码属于前一种情况:document.Rev==null