调试选项接受函数而不是布尔值:
mongoose.set("debug", function (collection, method, paramA, paramB, paramC) {
console.log(collection)
console.log(method)
console.log(paramA)
console.log(paramB)
console.log(paramC)
})
我提出的理由paramA, paramB, paramC
是因为参数取决于所使用的方法和选项:
Person.create({firstName: "john"}, callback)
// people
// insert
// {firstName: "john"}
// undefined
// undefined
Person.update({firstName: "john"}, {lastName: "doe"}, {new: true}, callback);
// people
// update
// {firstName: "john"}
// {$set: {lastName: "doe"}}
// {new: true}
Person.find({firstName: "john"}, callback);
// people
// find
// {firstName: "john"}
// undefined
// undefined
Person.find({firstName: "john"}, {limit: 1}, callback);
// people
// find
// {firstName: "john"}
// {limit: 1}
// undefined
正在记录的信息是Mongodb输入,而不是Mongoose输入。您可以在update()
方法,paramB
结果是{$set: {lastName: "doe"}}
。 Mongoose 在幕后转换更新以供使用$set
,这就是记录的原因。
由此,您可以轻松地将其格式化为您想要的格式,process.stdout.write()