Sunday, 16 April 2017

Mongoose find() query in NodeJs bot

I have the connection settings as below:

    mongoose.connect('mongodb://127.0.0.1:27017/cpfdb');
    var Schema = mongoose.Schema;
    var definitionSchema = new Schema({
    type: String,
    term: String,
    desccription: String
    });
    var Defintion = mongoose.model('Definition', definitionSchema);
    module.exports = Defintion;

I'm making a query as below:

Defintion.find({term: 'cpf life'}, function (err, definition) {
                    if (err) {
                        session.send("Something went wrong with the mongoose query: " + err);
                    } else {
                        session.send("I will define " + termToDefine + " for you...");
                        session.send(definition);
                    }
                });

However, I keep getting the error:

events.js:141
      throw er; // Unhandled 'error' event
      ^

TypeError: key.replace is not a function
    at DefaultLocalizer.escapeKey (/Users/user/Desktop/GitHub Projects/cpfbot/node_modules/botbuilder/lib/DefaultLocalizer.js:204:20)
    at DefaultLocalizer.createKey (/Users/user/Desktop/GitHub Projects/cpfbot/node_modules/botbuilder/lib/DefaultLocalizer.js:196:33)
    at DefaultLocalizer.trygettext (/Users/user/Desktop/GitHub Projects/cpfbot/node_modules/botbuilder/lib/DefaultLocalizer.js:69:24)
    at DefaultLocalizer.gettext (/Users/user/Desktop/GitHub Projects/cpfbot/node_modules/botbuilder/lib/DefaultLocalizer.js:86:21)
    at Session.vgettext (/Users/user/Desktop/GitHub Projects/cpfbot/node_modules/botbuilder/lib/Session.js:538:35)
    at Session.createMessage (/Users/user/Desktop/GitHub Projects/cpfbot/node_modules/botbuilder/lib/Session.js:521:24)
    at Session.sendLocalized (/Users/user/Desktop/GitHub Projects/cpfbot/node_modules/botbuilder/lib/Session.js:179:26)
    at Session.send (/Users/user/Desktop/GitHub Projects/cpfbot/node_modules/botbuilder/lib/Session.js:168:48)
    at /Users/user/Desktop/GitHub Projects/cpfbot/app.js:38:33
    at Query.<anonymous> (/Users/user/Desktop/GitHub Projects/cpfbot/node_modules/mongoose/lib/model.js:3709:16)
    at /Users/user/Desktop/GitHub Projects/cpfbot/node_modules/mongoose/node_modules/kareem/index.js:273:21
    at /Users/user/Desktop/GitHub Projects/cpfbot/node_modules/mongoose/node_modules/kareem/index.js:127:16
    at nextTickCallbackWith0Args (node.js:420:9)
    at process._tickCallback (node.js:349:13)

I checked with the mongoldb shell (without using mongoose) and the query is working fine. I can't find any information on key.replace is not a function...



via Sadeep

No comments:

Post a Comment