[英]What is the difference between model and model._doc in mongoose Models?
I'm new to java script and I'm building a graphql API with mongoose and when I want to return a result of myModel.find() using mongoose I see that there is a difference between model and model._doc . 我是Java脚本的新手,并且正在使用猫鼬构建graphql API,并且当我想使用猫鼬返回myModel.find()的结果时,我发现model和model._doc之间存在差异。 in this code
在这段代码中
return {
...model._doc
}
everything is OK and can get the result but when I code like this 一切都OK,可以得到结果,但是当我这样编码时
return{
...model
}
I get an error when I want to retrieve the data. 我想检索数据时出现错误。 when I print them they are exactly the same as I see.
当我打印它们时,它们与我所看到的完全相同。
The model
object is a mongoose object and not a normal JSON object, and to get data from the model object you should use toJSON
method. model
对象是猫鼬对象,而不是普通的JSON对象,要从模型对象获取数据,应使用toJSON
方法。
_doc
is an internal property and you shouldn't be using it, if they changed it your application will break. _doc
是一个内部属性,您不应该使用它,如果他们更改了它,则您的应用程序将_doc
。
model.toJSON()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.