couchDB数据库根问题

couchdDB dbroot issue

本文关键字:问题 数据库 couchDB      更新时间:2023-09-26

我正在使用couchdb。我是新手。我不知道用dbroot值来代替"db/"。我从coucdb教程中获得了这段代码。提前感谢您的帮助。

//使用命名空间来保护函数和变量名的范围

 var poq = {
//Some variables global to the local namespace ("poq")
root: "http://localhost:5984/",
dbroot: "db/",
max_quotes: 6,
//Invoked when the HTML page is first loaded
loadPage: function()
{
    var six_latest = poq.root + "poquotes/_design/document/_view/by_year?&limit="
        + poq.max_quotes + "&descending=true&callback=?";
    $.getJSON(six_latest, poq.handleMainQuotes);
    $('#donewquote').click(function() {
        var db_link = poq.dbroot + "poquotes";
        var record = {
            "type": "quote",
            "author": $("#author").val(),
            "text": $("#text").val(),
            "work": {
                "title": $("#title").val(),
                "link": $("#link").val(),
                "year": parseInt($("#year").val())
            }
        };
        $.ajax({
            url : db_link,
            data : JSON.stringify(record),
            contentType : "application/json", 
            type : 'POST',
            processData : false,
            dataType : "json",
            success : function(resp) {
                alert("New document created: " + JSON.stringify(resp));
            }
        });
        return false;
    });
    //Set up the collapsible form for adding new quotes
    $('#popup').click(function(){
        $("#newquote").slideToggle();
    });
    //Start out with the create quote form collapsed
    $("#newquote").slideToggle();
},
//Invoked with the result of the AJAX call to load quote documents
handleMainQuotes: function(json)
{
    //Load up to six records, as available
    quote_count = Math.min(poq.max_quotes, json["total_rows"])
    for (var i=0; i<quote_count; i++) {
        var doc = json["rows"][i]["value"]
        var year = doc["work"]["year"].toString()
        var title = doc["work"]["title"].toString()
        var link = doc["work"]["link"].toString()
        //Create an HTML snippet from the fields of each quote document
        qblock = $("<div class='span4 featured-quote'></div>")
          .append("<h2>" + doc["author"] + "</h2>")
          .append("<p style='font-size: 80%; height: 8em;'>" + doc["text"] + "</p>")
          .append("<p>" + year + "</p>")
          .append("<p><a href='" + link + "'>" + title + "</a></p>")
          .append("<p><a class='btn' href='#'>View details &raquo;</a></p>")
        //jQuery's eq selector to find the target div corresponding to the loop index
        $('div.featured-quote:eq(' + i.toString() + ')').replaceWith(qblock);
    }
},

}

这里的dbroot似乎是数据库的名称。如果你还没有创建数据库,你可以使用:

curl -X PUT http://localhost:5984/mynewdatabase

作为CouchDB的新手,我建议您从《最终指南》开始(http://guide.couchdb.org)