Javascript Couchdb`nano`模块-未经处理的拒绝-不是对象上的函数

Javascript Couchdb`nano`模块-未经处理的拒绝-不是对象上的函数,javascript,node.js,couchdb,couchdb-nano,Javascript,Node.js,Couchdb,Couchdb Nano,我将CouchdbUpdate函数添加到我的代码中,这是可以的,但当我在bot.onText(/^[\/!\35;]start$/,msg=>{中使用该函数时,我出现以下错误: Unhandled rejection TypeError: alice.update is not a function at Object.bot.onText.msg [as callback] 我该如何解决这个问题? 这是我的代码: var nano = require('nano')('http:/

我将Couchdb
Update
函数添加到我的代码中,这是可以的,但当我在
bot.onText(/^[\/!\35;]start$/,msg=>{
中使用该函数时,我出现以下错误:

Unhandled rejection TypeError: alice.update is not a function
    at Object.bot.onText.msg [as callback] 
我该如何解决这个问题? 这是我的代码:

var nano = require('nano')('http://localhost:5984');
// clean up the database we created previously 
nano.db.destroy('alice', function() {
  // create a new database 
  nano.db.create('alice', function() {
  var alice = nano.use('alice');
                                        /////   update Function
 alice.update = function(obj, key, callback){
 var db = this;
 db.get(key, function (error, existing){ 
    if(!error) obj._rev = existing._rev;
    db.insert(obj, key, callback);
 });
};

  });
});



bot.onText(/^[\/!#]start$/, msg => {
                                    /////  using update 
   var alice = nano.use('alice');
 alice.update({ crazay: true }, 'rabbit', function(err, body, header) {
      if (err) {
        console.log('[alice.insert] ', err.message);
        return;
      }
      console.log('you have updated the rabbit.')
      console.log(body);
    });
 const opts = {
    reply_to_message_id: msg.message_id,
    reply_markup: JSON.stringify({
      keyboard: [['TEST']],
      resize_keyboard:true,
      one_time_keyboard: true
    })
  };
  bot.sendMessage(msg.chat.id, `Stored In DB`, opts);
});

我自己解决了,你应该在
bot.onText

var nano = require('nano')('http://localhost:5984');
// clean up the database we created previously 
nano.db.destroy('alice', function() {
  // create a new database 
  nano.db.create('alice', function() {
  var alice = nano.use('alice');
  });
});



bot.onText(/^[\/!#]start$/, msg => {
                                    /////  using update 
   var alice = nano.use('alice');
                                        /////   update Function
 alice.update = function(obj, key, callback){
 var db = this;
 db.get(key, function (error, existing){ 
    if(!error) obj._rev = existing._rev;
    db.insert(obj, key, callback);
 });
};

 alice.update({ crazay: true }, 'rabbit', function(err, body, header) {
      if (err) {
        console.log('[alice.insert] ', err.message);
        return;
      }
      console.log('you have updated the rabbit.')
      console.log(body);
    });
 const opts = {
    reply_to_message_id: msg.message_id,
    reply_markup: JSON.stringify({
      keyboard: [['TEST']],
      resize_keyboard:true,
      one_time_keyboard: true
    })
  };
  bot.sendMessage(msg.chat.id, `Stored In DB`, opts);
});