You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by "A. Lotfi" <ma...@yahoo.com> on 2012/10/15 05:02:16 UTC

newbie question, add new documents

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


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

Re: newbie question, add new documents

Posted by "matt j. sorenson" <ma...@sorensonbros.net>.
> 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<http://127.0.0.1:5984/_utils/database.html?addressbook>
>>
>>
I wonder if the orignal poster was looking simply for a way to add an
entire document at a time, rather than field by field, as the blog post
doesn't make it clear and I've found that it isn't immediately obvious to
new futon users (it wasn't obvious to me, I discovered it by accident) that
when editing or creating a new document, one is able to click on the
'Source' tab, then double-click in the Source area to have an editable text
area in which to type or paste an entire body of json - 1 whole document at
a time. When you already have json, this is obviously more efficient than
field by field when constrained to the futon user interface.

incidentally also a potential ux improvement for futon2 :)
--
*matt j. sorenson*

Re: newbie question, add new documents

Posted by "john.tiger" <jo...@gmail.com>.
On 10/15/2012 02:10 AM, Dave Cottlehuber wrote:
> On 15 October 2012 05:02, A. Lotfi <ma...@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
>


Re: newbie question, add new documents

Posted by Dave Cottlehuber <dc...@jsonified.com>.
On 15 October 2012 05:02, A. Lotfi <ma...@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

Re: newbie question, add new documents

Posted by Aurélien Bénel <au...@utt.fr>.
> http://blog.edparcell.com/using-jquery-and-couchdb-to-build-a-simple-we
>> Since this is the very beginning of the tutorial, I suppose the author wanted you to simply add them one by one.
>>> You can use any http library to add documents, but command line cURL is a very good place to start off from with CouchDB.

Sorry to insist, but I think that if the author of the tutorial wanted you to use curl (or RESTClient), he would have explained how to do it. Since he didn't, I think he wanted you to use Futon (the user interface you've just used to create the database).

Don't worry, you'll have plenty of other opportunities for using the REST interface directly ;)


Regards,

Aurélien




Re: newbie question, add new documents

Posted by Aurélien Bénel <au...@utt.fr>.
Hi Lotfi,

> 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. ?

Since this is the very beginning of the tutorial, I suppose the author wanted you to simply add them one by one.


Regards,

Aurélien