Couchdb spits out a url that is like this
http://127.0.0.1:5984/roxanne/_design/request/_view/images
This has my database and all my json. The problem is I want all the json to be parsed and sent to a different url called /getDocuments. I am using node, express, nano.
In my server.js I have this code.
app.get('/getDocuments', function(req, res){
var roxanne = nano.use('roxanne');
nano.db.get('roxanne', function(err, body) {
if (!err) {
console.log(body);
}
res.json(body);
});
})
Which is not what I want it print out this:
{
"db_name": "roxanne",
"doc_count": 7,
"doc_del_count": 2,
"update_seq": 12,
"purge_seq": 0,
"compact_running": false,
"disk_size": 204904,
"data_size": 3369,
"instance_start_time": "1375974435712463",
"disk_format_version": 6,
"committed_update_seq": 12
}
Which doesnt help, I want all of the json that the url prints out and parsed. I also did a little experiment and it said unexpected token ILLEGAL.
'{"total_rows":6,"offset":0,"rows":[
I found this which is my problem, but not exactly sure what it means. How to get past the "total_rows" when parsing JSON from CouchDB
So my question is:
How do I get that localhost url with all the json into /getDocument so that later in my project I can just get the json and each through it.
THANK YOU! If you have any questions please ask.
ps: My experiment was this:
var json = '{"total_rows":6,"offset":0,"rows":[
{"id":"American_Airlines","key":"American_Airlines","value":{"_id":"American_Airlines","_rev":"1-d915fad8f624769d274794717b60311f","name":"American_Airlines","industry":"Flight","employee_count":"820,712,807","revenue":"$1,219,280,981","lead_source":"Linkedin","use_case":"exec manag","sales_cycle":"80","adm":"Adm goes here","se":"Se goes here","path":"assets/upload-images/2013/08/1375890760.png","fileTime":"1375890760"}},
{"id":"Dicks_Sporting_Goods","key":"Dicks_Sporting_Goods","value":{"_id":"Dicks_Sporting_Goods","_rev":"1-90cc5645b417ba0658aa7dcf5d576a51","name":"Dicks_Sporting_Goods","industry":"Store","employee_count":"3,098,089","revenue":"$2,918,798","lead_source":"website","use_case":"seo, stuff, moar stuff","sales_cycle":"20","adm":"Adm goes here","se":"Se goes here","path":"assets/upload-images/2013/08/1375890818.png","fileTime":"1375890818"}},
{"id":"FedEx","key":"FedEx","value":{"_id":"FedEx","_rev":"2-709a9dba4723b77fb6c40b3f0110ef97","name":"FedEx","industry":"industy here","employee_count":"100,000,000,000,000","revenue":"$10,000,000,000,000,000,000","lead_source":"twitter","use_case":"use case","sales_cycle":"90","adm":"adm goes here","se":"se goes here","path":"assets/upload-images/2013/08/1375888322.png","fileTime":"1375888322"}},
{"id":"Five_Guys","key":"Five_Guys","value":{"_id":"Five_Guys","_rev":"1-936c3f2da5e20031d618b005e5080181","name":"Five_Guys","industry":"Burger Joint","employee_count":"452,342,362","revenue":"$2,352,235,235,234","lead_source":"linkedin","use_case":"Data","sales_cycle":"20","adm":"Adm goes here","se":"Se goes here","path":"assets/upload-images/2013/08/1375892543.png","fileTime":"1375892543"}},
{"id":"hulu","key":"hulu","value":{"_id":"hulu","_rev":"1-d60340fde35feabbf78463c28684f3e3","name":"hulu","industry":"Internet","employee_count":"124,243,521,346","revenue":"$34,624,573,467,245,643","lead_source":"Facebook","use_case":"unkown","sales_cycle":"333","adm":"Kenneth","se":"MEMMEMEME","path":"assets/upload-images/2013/08/1375892898.jpg","fileTime":"1375892898"}},
{"id":"jiffy_lube","key":"jiffy_lube","value":{"_id":"jiffy_lube","_rev":"1-6c6b6fe2213c541b9c437aa8c47286fd","name":"jiffy_lube","industry":"industy here","employee_count":"12,124,124,124","revenue":"$23,897,629,871","lead_source":"scrubs","use_case":"something ","sales_cycle":"90","adm":"Adm goes here","se":"Se goes here","path":"assets/upload-images/2013/08/1375890322.jpg","fileTime":"1375890322"}}
]}';
var obj = JSON.parse(json);
res.json(obj)
Which outputted:
var json = '{"total_rows":6,"offset":0,"rows":[
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
unexpected token ILLEGAL
PS: This worked, so the problem is the total_rows, but I still need to figure out how to get my localhost to a different url.
var json = '{"id":"American_Airlines","key":"American_Airlines","value":{"_id":"American_Airlines","_rev":"1-d915fad8f624769d274794717b60311f","name":"American_Airlines","industry":"Flight","employee_count":"820,712,807","revenue":"$1,219,280,981","lead_source":"Linkedin","use_case":"exec manag","sales_cycle":"80","adm":"Adm goes here","se":"Se goes here","path":"assets/upload-images/2013/08/1375890760.png","fileTime":"1375890760"}}';
var obj = JSON.parse(json);
res.json(obj)
This worked,but like I said Im trying to figure out the main problem still then I will focus on the total_rows problem. Sorry I asked multiple questions in one. I think that may be confusing people.
EDIT/ANSWER
Retrieving all Documents from couchdb using Node.js
This post right here helped me out so much! It solved many problems that I encountered. For future people that ever need help.
db.view
is what i was looking for! Thank you!
You are querying for the database stats, not for a database document. When you want to retrieve a specific document, this is how you use the driver:
var roxanne = nano.use('roxanne');
roxanne.get('document_id', function(err, body) {
console.log(err, body);
});
Note the roxanne.get
instead of nano.get
.
If you want to get all the documents,
var roxanne = nano.use('roxanne');
roxanne.bulk('_all_docs', {include_docs: true}, function(err, docs) {
console.log(err, docs);
});