couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Cottlehuber <...@jsonified.com>
Subject Re: newbie question, add new documents
Date Mon, 15 Oct 2012 08:10:40 GMT
On 15 October 2012 05:02, A. Lotfi <majidnakit@yahoo.com> wrote:
> Hi,
> I am new to couchDB, just started to read tutorials about it, I found this one :
> http://blog.edparcell.com/using-jquery-and-couchdb-to-build-a-simple-we

Welcome!

> In the first page it says :
>
>  The initial version of our webapp will let us store a mobile number for each person,
so add the following 2 documents:
> view plaincopy to clipboardprint?
>         1. {"type": "address", "name": "Fred", "mobile": "555-0001"}
>         2. {"type": "address", "name": "Barney", "mobile": "555-0002"}
>
>
> Is there any way to add ducument as the above jsons, or just add one by one from :
>
> http://127.0.0.1:5984/_utils/database.html?addressbook
>
>
> by clicking New Document. ?
> thanks

You can use any http library to add documents, but command line cURL
is a very good place to start off from with CouchDB.

You can do this to upload a single JSON doc inline, note that CouchDB
will assign a UUID for you in this case:

    curl -Hcontent-type:application/json -XPOST
http://localhost:5984/test1/ --data-binary '<document>'

or include the UUID yourself:

    curl -Hcontent-type:application/json -XPUT
http://localhost:5984/test1/newdoc --data-binary '<document>'

Where document is the JSON body you have above.

You can also use the bulk_docs interface to upload multiple JSON docs,
when they're in a single file:

http://www.muse.net.nz/blog/2011/12/16/munging-posterous-with-couchdb/

I suggest you use yajl or some other JSON linter to confirm your JSON
is valid before uploading it. A really common issue is that your text
is not UTF8, even though the characters are valid.

A+
Dave

Mime
View raw message