You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Lauren Dahlin <ld...@simons-rock.edu> on 2012/02/14 06:25:35 UTC

VERY Basic Question

I am very new to couchdb. I need it to access an Amazon public dataset  
using EC2. I am running an Ubuntu instance, have successfully mounted  
the file, and can view the couchdb browser interface. However, I can't  
figure out how to get access to the existing databases which are  
in .couch format. I have several couch files in a folder ("/db") in  
the instance. I've tried:
curl -X GET http://localhost:5984/db
{"error":"not_found","reason":"no_db_file"}
curl -X GET http://localhost:5984/db/filname.couch
{"error":"not_found","reason":"no_db_file"}

Sorry to junk up the mailing list with such a basic question, but I'm  
totally stuck.

Humbly,
Lauren

Re: VERY Basic Question

Posted by Jens Alfke <je...@couchbase.com>.
On Feb 15, 2012, at 6:37 AM, Lauren Dahlin wrote:

First, does anyone have any very simple resources for learning how to use views?

Have you read the O’Reilly book, which is online at http://guide.couchdb.org ? It’s got some decent tutorial stuff about how to use views, particularly the “View Cookbook For SQL Jockeys<http://guide.couchdb.org/draft/cookbook.html>” chapter.

—Jens

Re: VERY Basic Question

Posted by Simon Metson <si...@googlemail.com>.
Hi 


On Wednesday, 15 February 2012 at 15:12, Simon Metson wrote:

> > > 
> > 
> > 
> > 
> > 
> 
> That's currently not done easily. You'd need to hit _all_docs with a limit parameter (e.g. http://localhost:5984/demo/_all_docs?limit=100) then push the result back into your subset database. Give me some time and I'll knock up a python script to do it...
> 
> 

Quickly hacked up script:



https://github.com/drsm79/couch-generics/blob/master/scripts/fetch_subset.py

Should have no dependencies other than python2.6. Not extensively tested, patches welcome etc.
Cheers
Simon

Re: VERY Basic Question

Posted by Simon Metson <si...@googlemail.com>.
Hi Lauren, 


On Wednesday, 15 February 2012 at 14:49, Lauren Dahlin wrote:

> Also, I am working on a very large database so testing is difficult. 
> How can I sample (doesn't have to be random) a given number of 
> documents?
That's currently not done easily. You'd need to hit _all_docs with a limit parameter (e.g. http://localhost:5984/demo/_all_docs?limit=100) then push the result back into your subset database. Give me some time and I'll knock up a python script to do it...
> > First, does anyone have any very simple resources for learning how 
> > to use views? Coming from a limited SQL background, I'm so confused. 
> > What I am really having trouble with is how to query subvalues. 
> > (Also, is "subvalue" the right word?) For example, say I have:
> > { "_id" : "bc2a41170621c326ec68382f846d5764", "_rev" : "2612672603", 
> > "item" : "apple", "prices" : { "Fresh Mart" : 1.59, "Price Max" : 
> > 5.99, "Apples Express" : 0.79 } }
> > (example from http://answers.oreilly.com/topic/1396-running-a-couchdb-query-using-mapreduce/)
> > How would I only return the price associated with "Fresh Mart" for 
> > every ID containing a Freshmart price?
> > 
> > 
> 
> 
> 


You need to write a map reduce view, then query it appropriately. The following will return a row for every price, keyed on the store:

function(doc) {
  if (doc.prices){
    for (store in doc.prices){
      emit(store, doc.prices[store]);
    }
  }
}


That'll give you back data like:

{"total_rows":6,"offset":0,"rows":[ {"id":"6152bfe666b48bf57063b055120003df","key":"Apples Express","value":0.79}, {"id":"6152bfe666b48bf57063b05512000c88","key":"Bananas 4 U","value":1.79}, {"id":"6152bfe666b48bf57063b055120003df","key":"Fresh Mart","value":1.59}, {"id":"6152bfe666b48bf57063b05512000c88","key":"Fresh Mart","value":2.79}, {"id":"6152bfe666b48bf57063b055120003df","key":"Price Max","value":5.99}, {"id":"6152bfe666b48bf57063b05512000c88","key":"Price Max","value":3.99} ]}

You might want to add the item into the views key, so you can query for the price of apples at Fresh Mart:

function(doc) {
  if (doc.prices){
    for (store in doc.prices){
      emit([doc.item, store], doc.prices[store]);
    }
  }
}


That returns:
{"total_rows":6,"offset":0,"rows":[ {"id":"6152bfe666b48bf57063b055120003df","key":["apple","Apples Express"],"value":0.79}, {"id":"6152bfe666b48bf57063b055120003df","key":["apple","Fresh Mart"],"value":1.59}, {"id":"6152bfe666b48bf57063b055120003df","key":["apple","Price Max"],"value":5.99}, {"id":"6152bfe666b48bf57063b05512000c88","key":["banana","Bananas 4 U"],"value":1.79}, {"id":"6152bfe666b48bf57063b05512000c88","key":["banana","Fresh Mart"],"value":2.79}, {"id":"6152bfe666b48bf57063b05512000c88","key":["banana","Price Max"],"value":3.99} ]}
I can query it like http://localhost:5984/demo/_design/demo/_view/items?startkey=[%22apple%22]&endkey=[%22apple%22,%20{}] (http://localhost:5984/demo/_design/demo/_view/items?startkey=%5B%22apple%22%5D&endkey=%5B%22apple%22,%20%7B%7D%5D) to get just apples:
{"total_rows":6,"offset":0,"rows":[ {"id":"6152bfe666b48bf57063b055120003df","key":["apple","Apples Express"],"value":0.79}, {"id":"6152bfe666b48bf57063b055120003df","key":["apple","Fresh Mart"],"value":1.59}, {"id":"6152bfe666b48bf57063b055120003df","key":["apple","Price Max"],"value":5.99} ]}
Or like http://localhost:5984/demo/_design/demo/_view/items?key=["apple","Fresh Mart"] (http://localhost:5984/demo/_design/demo/_view/items?key=%5B%22apple%22,%22Fresh%20Mart%22%5D) to get just Fresh Mart's prices:
{"total_rows":6,"offset":1,"rows":[ {"id":"6152bfe666b48bf57063b055120003df","key":["apple","Fresh Mart"],"value":1.59} ]}

Hope that helps
Simon



Re: VERY Basic Question

Posted by Lauren Dahlin <ld...@simons-rock.edu>.
Also, I am working on a very large database so testing is difficult.  
How can I sample (doesn't have to be random) a given number of  
documents?

On Feb 15, 2012, at 9:37 AM, Lauren Dahlin wrote:

> First, does anyone have any very simple resources for learning how  
> to use views? Coming from a limited SQL background, I'm so confused.  
> What I am really having trouble with is how to query subvalues.  
> (Also, is "subvalue" the right word?) For example, say I have:
> { "_id" : "bc2a41170621c326ec68382f846d5764", "_rev" : "2612672603",  
> "item" : "apple", "prices" : { "Fresh Mart" : 1.59, "Price Max" :  
> 5.99, "Apples Express" : 0.79 } }
> (example from http://answers.oreilly.com/topic/1396-running-a-couchdb-query-using-mapreduce/)
> How would I only return the price associated with "Fresh Mart" for  
> every ID containing a Freshmart price?
>
> Second of all, I wanted to thank Manokaran K for pointing me in the  
> right direction. I don't know how many Amazon datasets are in  
> couchdb (who knows, it might only be the one I'm interested in), but  
> in case any other people are searching for how to get access to an  
> Amazon public dataset in couchdb over EC2, I thought I would post  
> what was successful for me. I tried to change the default directory  
> in local.ini to where I had mounted the volume, but this resulted in  
> couchdb hanging indefinitely at the startup. I ended up mounting the  
> volume into the default directory and then using chown to change  
> permissions on the directory to couchdb. This worked for me.
>
> On Feb 14, 2012, at 12:33 AM, Manokaran K wrote:
>
>> On Tue, Feb 14, 2012 at 11:00 AM, Manokaran K <ma...@gmail.com>  
>> wrote:
>>
>>>
>>> On Tue, Feb 14, 2012 at 10:55 AM, Lauren Dahlin <ldahlin08@simons-rock.edu
>>>> wrote:
>>>
>>>> I am very new to couchdb. I need it to access an Amazon public  
>>>> dataset
>>>> using EC2. I am running an Ubuntu instance, have successfully  
>>>> mounted the
>>>> file, and can view the couchdb browser interface. However, I  
>>>> can't figure
>>>> out how to get access to the existing databases which are  
>>>> in .couch format.
>>>> I have several couch files in a folder ("/db") in the instance.  
>>>> I've tried:
>>>> curl -X GET http://localhost:5984/db
>>>> {"error":"not_found","reason":**"no_db_file"}
>>>> curl -X GET http://localhost:5984/db/**filname.couch<http://localhost:5984/db/filname.couch 
>>>> >
>>>> {"error":"not_found","reason":**"no_db_file"}
>>>>
>>>>
>>> You'll have to do curl -X GET http://localhost:5984/name_of_db.
>>>
>>> Hope that helps.
>>>
>>> best,
>>> mano
>>>
>>
>>
>> Your .couch files should be under /usr/local/var/lib/couchdb if you
>> installed couchdb in /usr/local. I don't think it'll work if you  
>> have it
>> under 'db' directory!
>


Re: VERY Basic Question

Posted by Lauren Dahlin <ld...@simons-rock.edu>.
First, does anyone have any very simple resources for learning how to  
use views? Coming from a limited SQL background, I'm so confused. What  
I am really having trouble with is how to query subvalues. (Also, is  
"subvalue" the right word?) For example, say I have:
{ "_id" : "bc2a41170621c326ec68382f846d5764", "_rev" : "2612672603",  
"item" : "apple", "prices" : { "Fresh Mart" : 1.59, "Price Max" :  
5.99, "Apples Express" : 0.79 } }
(example from http://answers.oreilly.com/topic/1396-running-a-couchdb-query-using-mapreduce/)
How would I only return the price associated with "Fresh Mart" for  
every ID containing a Freshmart price?

Second of all, I wanted to thank Manokaran K for pointing me in the  
right direction. I don't know how many Amazon datasets are in couchdb  
(who knows, it might only be the one I'm interested in), but in case  
any other people are searching for how to get access to an Amazon  
public dataset in couchdb over EC2, I thought I would post what was  
successful for me. I tried to change the default directory in  
local.ini to where I had mounted the volume, but this resulted in  
couchdb hanging indefinitely at the startup. I ended up mounting the  
volume into the default directory and then using chown to change  
permissions on the directory to couchdb. This worked for me.

On Feb 14, 2012, at 12:33 AM, Manokaran K wrote:

> On Tue, Feb 14, 2012 at 11:00 AM, Manokaran K <ma...@gmail.com>  
> wrote:
>
>>
>> On Tue, Feb 14, 2012 at 10:55 AM, Lauren Dahlin <ldahlin08@simons-rock.edu
>>> wrote:
>>
>>> I am very new to couchdb. I need it to access an Amazon public  
>>> dataset
>>> using EC2. I am running an Ubuntu instance, have successfully  
>>> mounted the
>>> file, and can view the couchdb browser interface. However, I can't  
>>> figure
>>> out how to get access to the existing databases which are  
>>> in .couch format.
>>> I have several couch files in a folder ("/db") in the instance.  
>>> I've tried:
>>> curl -X GET http://localhost:5984/db
>>> {"error":"not_found","reason":**"no_db_file"}
>>> curl -X GET http://localhost:5984/db/**filname.couch<http://localhost:5984/db/filname.couch 
>>> >
>>> {"error":"not_found","reason":**"no_db_file"}
>>>
>>>
>> You'll have to do curl -X GET http://localhost:5984/name_of_db.
>>
>> Hope that helps.
>>
>> best,
>> mano
>>
>
>
> Your .couch files should be under /usr/local/var/lib/couchdb if you
> installed couchdb in /usr/local. I don't think it'll work if you  
> have it
> under 'db' directory!


Re: VERY Basic Question

Posted by Manokaran K <ma...@gmail.com>.
On Tue, Feb 14, 2012 at 11:00 AM, Manokaran K <ma...@gmail.com> wrote:

>
> On Tue, Feb 14, 2012 at 10:55 AM, Lauren Dahlin <ldahlin08@simons-rock.edu
> > wrote:
>
>> I am very new to couchdb. I need it to access an Amazon public dataset
>> using EC2. I am running an Ubuntu instance, have successfully mounted the
>> file, and can view the couchdb browser interface. However, I can't figure
>> out how to get access to the existing databases which are in .couch format.
>> I have several couch files in a folder ("/db") in the instance. I've tried:
>> curl -X GET http://localhost:5984/db
>> {"error":"not_found","reason":**"no_db_file"}
>> curl -X GET http://localhost:5984/db/**filname.couch<http://localhost:5984/db/filname.couch>
>> {"error":"not_found","reason":**"no_db_file"}
>>
>>
> You'll have to do curl -X GET http://localhost:5984/name_of_db.
>
> Hope that helps.
>
> best,
> mano
>


Your .couch files should be under /usr/local/var/lib/couchdb if you
installed couchdb in /usr/local. I don't think it'll work if you have it
under 'db' directory!

Re: VERY Basic Question

Posted by Manokaran K <ma...@gmail.com>.
On Tue, Feb 14, 2012 at 10:55 AM, Lauren Dahlin
<ld...@simons-rock.edu>wrote:

> I am very new to couchdb. I need it to access an Amazon public dataset
> using EC2. I am running an Ubuntu instance, have successfully mounted the
> file, and can view the couchdb browser interface. However, I can't figure
> out how to get access to the existing databases which are in .couch format.
> I have several couch files in a folder ("/db") in the instance. I've tried:
> curl -X GET http://localhost:5984/db
> {"error":"not_found","reason":**"no_db_file"}
> curl -X GET http://localhost:5984/db/**filname.couch<http://localhost:5984/db/filname.couch>
> {"error":"not_found","reason":**"no_db_file"}
>
>
You'll have to do curl -X GET http://localhost:5984/name_of_db.

Hope that helps.

best,
mano