Debugging Mongoose调试写入STDERR?

Debugging Mongoose调试写入STDERR?,debugging,mongoose,stdout,options,stderr,Debugging,Mongoose,Stdout,Options,Stderr,第一个问题,啊 有人知道/有关于为什么mongoose将其调试日志写入stderr的信息吗?是否仍要将其写入标准输出?调试选项接受函数而不是布尔值: mongoose.set("debug", function (collection, method, paramA, paramB, paramC) { console.log(collection) console.log(method) console.log(paramA) console.log(para

第一个问题,啊


有人知道/有关于为什么mongoose将其调试日志写入stderr的信息吗?是否仍要将其写入标准输出?

调试选项接受函数而不是布尔值:

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()

太棒了,谢谢。使用“debug”负责生成日志的事实,我在mongoose/lib/collection.js:console.error('\x1B[0;36s:\x1B[0m%s.%s(%s)%s%s%s%s',self.name,I,print(args[0]),print(args[1]),print(args[2]),print(args[3])中找到了这一行