我运行了此脚本以使用猫鼬连接到MongoDB。
const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost/curious", { useNewUrlParser: true });
const db = mongoose.connection;
const dbLog = (msg) => {
console.log(`[DATABASE] [SUCCESS] ${msg}`);
}
const dbLogError = (msg) => {
console.error(`[DATABASE] [ERROR] ${msg}`);
}
db.on("error", dbLogError("Database connection failure"));
db.once("open", () => {
dbLog("Database connection successful");
})
mongoose.connection.close()
我收到以下错误
PS D:\scripts> node .\dbUtils.js
[DATABASE] [ERROR] Database connection failure
events.js:110
throw new ERR_INVALID_ARG_TYPE('listener', 'Function', listener);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received undefined
at checkListener (events.js:110:11)
at _addListener (events.js:347:3)
at NativeConnection.addListener (events.js:405:10)
at Object.<anonymous> (D:\Workspace\curious-backend\scripts\dbUtils.js:13:4)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47 {
code: 'ERR_INVALID_ARG_TYPE'
}
这是什么错误,我该如何解决?
Stackoverflow会让我在没有更多文本的情况下发帖,所以,你们所有人都过得很愉快。这是艰难的时期。爱自己,多保重。
答案 0 :(得分:1)
看起来像问题在 [BindProperty]
public Cars Car { get; set; }
public IList<Brands> Brands { get; set; }
public void OnGet()
{
Brands = new List<Brands> { new Brands { Brand="teta" }, new Brands { Brand="tetb" } };
}
public async Task<IActionResult> OnPost(Cars Car) {
return Page();
}
侦听器中,因为它期望功能。更新:
error
收件人:
db.on("error", dbLogError("Database connection failure"));
它应该可以工作!