简体   繁体   English

猫鼬模型中的model和model._doc有什么区别?

[英]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.

相关问题 用猫鼬定义模型时allowNull和required有什么区别 - What's the difference between allowNull and required when defining a model with mongoose Ember.js:对象模型和模型之间有什么区别? - Ember.js: what's the difference between the object model and model? XRM对象模型和FormContext有什么区别? - What is difference between XRM Object Model and FormContext? 骨干模型上的initialize和constructor之间有什么区别 - What's the difference between initialize and constructor on a backbone model Ember - 控制器的内容和模型属性之间有什么区别 - Ember - What's the difference between controller's content and model property mongoose中id和_id有什么区别? - What is the difference between id and _id in mongoose? mongoose.Promise 和 promisifyAll 有什么区别? - What the difference between mongoose.Promise and promisifyAll? 我正在尝试创建一个文档来使用 mongoose 进行建模,但是 model.create() 没有返回任何承诺 - I am trying to create a doc to model with mongoose but model.create() does not return any promise 环回中的公共模型和服务器模型有什么区别? - What is the difference between common and server models in loopback? mongoose.Schema() 和 new mongoose.Schema() 有什么区别? - What is the difference between mongoose.Schema() and new mongoose.Schema()?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM