0

I am trying to fetch data from couch and i follwed the code below

  var request = require('request')
var nano = require('nano')('http://localhost:5984/user');
var url = 'http://127.77.3.1:5984/'
var db = 'users2/'
var id = 'document_id'



exports.insertdata = function (req, res) {
  var data = req.body;
  var item = { 
    name: data.name,
    skills: data.skills, 
    experience: data.experience 
  };

nano.insert(item,(err, result) => {
  if(!err){
    //awesome
  }if(result){
     console.log(result)
    response = {status:'success',data:result};
  }
  res.send(response);
  });
};


exports.getdata = function (req, res) {
  nano.getDoc('25f2b6d1e5b83887a42c74bc9b000647',(err, result) => {
  if(!err){
    //awesome
    console.log(err)
  }if(result){console.log(result)
    console.log('inserted')
    response = {status:'success',data:result};
  }
   res.send(response);
  });
};

I am getting the following error

nano.getDoc is not a function

I am trying to fetch data from couch and i follwed the above code,i am not sure about the commands ....can anyone please suggest me some help..........

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
klp
  • 153
  • 1
  • 3
  • 14
  • Did [my post below](http://stackoverflow.com/questions/39701464/how-to-rtrive-data-from-db-in-couchdb-nodejs/39773354#39773354) answer your question? If it did then you may consider [accepting the answer](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) because right now other people searching for this problem see that your question has no good answer and may not read it. If it didn't answer your question then please comment on what is missing. I'm going through my old answers and I want to update them if they need any improvements. Thanks. – rsp Nov 10 '16 at 09:31

1 Answers1

0

There is no getDoc in nano as far as I know. There is get. Maybe try changing this:

nano.getDoc('25f2b6d1e5b83887a42c74bc9b000647', (err, result) => {
});

to:

nano.get('25f2b6d1e5b83887a42c74bc9b000647', (err, result) => {
});

and see if that works.

For example here is a simplest query to the CouchDB database that powers the npm registry:

var nano = require('nano');
var db = nano('https://skimdb.npmjs.com/registry');

db.get('rsp', (err, data) => {
  if (err) {
    console.log(err);
  } else {
    console.log(data);
  }
});

Here rsp is the document id, which is a module's name on npm.

In your case it might work if you change getDoc to get. For other function names see the documentation at:

rsp
  • 107,747
  • 29
  • 201
  • 177