couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "john.tiger" <>
Subject Re: newbie question, add new documents
Date Mon, 15 Oct 2012 10:05:24 GMT
On 10/15/2012 02:10 AM, Dave Cottlehuber wrote:
> On 15 October 2012 05:02, A. Lotfi <> wrote:
>> Hi,
>> I am new to couchDB, just started to read tutorials about it, I found this one :
> 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
>> 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:

Futon is a simple interface to do some admin on your db or do a simple 
insert or query.  from your example it does sound like you want to use 
the easiest way to get some initial or test data into your db - in that 
case curl and the command bulk_docs is an easy way to load a set of data 
- just note: with bulk_docs you need to structure your json to look like 
this  {"docs": [{json1},{json2}]}    - look up the wiki page on this.   
after you understand using couch commands from the command line using 
curl - then you could move to calling couchdb REST commands from a 
program using jquery, etc but this is a bit trickier with same origin 
policies, etc.

> 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

View raw message