我的连接设置如下:
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;
我正在进行如下查询:
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);
}
});
然而,我一直收到错误:
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)
我用mongoldb shell检查(不使用mongoose),查询工作正常。我在key.replace is not a function
...
答案 0 :(得分:1)
我认为你的问题与mongoose
无关。我认为它与:
session.send(definition);
Bot Framework具有内置localization支持,并首先尝试将您传递到session.send()
的所有内容作为key
解析为外部资源文件。 escape
方法执行以下操作:
key.replace(/:/g, "--").toLowerCase();
当然,假设您传入的key
是string
。请通过调试或使用简单的console.log
检查您传递给definition
的确切session.send()
。