incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "john.tiger" <john.tigernas...@gmail.com>
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 <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/

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
>


Mime
View raw message