Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在mongoose中的其他文档中使用相同模式时,如何不使用特定列_Node.js_Mongodb - Fatal编程技术网

Node.js 在mongoose中的其他文档中使用相同模式时,如何不使用特定列

Node.js 在mongoose中的其他文档中使用相同模式时,如何不使用特定列,node.js,mongodb,Node.js,Mongodb,例如,我有两个模式: var AppointmentSchema = new Schema({ _id : ObjectId, customerId: { type: Schema.Types.ObjectId, ref: 'User' }, staffId: { type: Schema.Types.ObjectId, ref: 'User' } },{ timestamps: true }); var SchemaA = new Schema({ _id : ObjectI

例如,我有两个模式:

var AppointmentSchema = new Schema({
_id : ObjectId,    
customerId: { type: Schema.Types.ObjectId, ref: 'User' },
staffId: { type: Schema.Types.ObjectId, ref: 'User' }
},{
    timestamps: true
});

var SchemaA = new Schema({
_id : ObjectId,
name : String,     
Staff : [{ type: Schema.Types.ObjectId, ref: 'User' }, Appointment: [AppointmentSchema] ] ,
Pending_Appointments: [AppointmentSchema],    
},{
timestamps: true
});

现在,正如您在SchemaA中看到的,我有一个使用AppointSchema的待定约会,在staff内部,我有一个对user的引用,还有一个名为appointment的子文档,它也使用AppointSchema(语法正确吗?)。所以我的问题是在预约时,我想使用相同的模式,但我想在插入时排除staffId,因为我不需要员工,因为我已经在里面了。有人能帮我吗。如果有人想指出制定计划的更好方法,你可以告诉我。谢谢。

举个例子。首先,在模式中有一些东西,但在插入的值中没有,这是毫无意义的


但无论如何,要解决这个问题,你可以做一件简单的事情。正如我所看到的,在您的模式中不需要重复的字段人员,因此当您使用AppointmentSchema输入模式A时,只需忽略该字段,它就可以完美地工作

该死的,我怎么会忘记mongodb就是这样工作的:p。如果你不插入,它将不会被计算。谢谢你,先生,实际上这样一个模式的原因是,当我插入待定的预约时,我将插入标记,但当有确认时,我将从待定的预约中删除该条目,然后将其放入预约中,但我不会插入标记,因为它不需要。有道理吗?或者这是一个错误的方法有时候我们错过了这样的事情,而不是一件大事。请不要叫我先生,这只是我表达敬意的方式。顺便说一句,你能回答我剩下的问题吗?你的方法看起来不错,但就我个人而言,我不太喜欢在MongoDB中使用引用,它们会让事情变得复杂和缓慢。(你可以做一些研究)。我说过你可以继续做你所拥有的。如果您解释第二个模式的用法,即模式A,也许我会更好地理解上下文。