请问mongoose的model怎么转成json对象
发布于 5 年前 作者 TJJ123456 2874 次浏览 来自 问答

我用model查询返回的model太大了,我现在只知道用JSON.stringfy()和JSON.parse()来回转换,请问还有什么方法可以转换吗

2 回复

Query.prototype.lean() Parameters bool «Boolean|Object» defaults to true Returns: «Query» this Sets the lean option.

Documents returned from queries with the lean option enabled are plain javascript objects, not MongooseDocuments. They have no save method, getters/setters or other Mongoose magic applied.

Example: new Query().lean() // true new Query().lean(true) new Query().lean(false)

Model.find().lean().exec(function (err, docs) { docs[0] instanceof mongoose.Document // false });

回到顶部