VersionError:找不到与ID匹配的文档

时间:2019-01-06 07:21:06

标签: node.js mongodb mongoose mongoose-schema

我和猫鼬在一起很困难。我想从一个集合中获取文档,并想立即将其保存到其他集合中。但是我面临版本错误。

我尝试删除__v属性,但仍然收到相同的错误。 下面是我的代码。它是强大功能的一部分,因此仅发布相关代码。

//appointment-schema.js  
const mongoose = require("mongoose");   
const Schema = mongoose.Schema;  
const AppointmentSchema = new Schema({  
providerId: { type: String, index: true },  
providerName: { type: String, index: true },  
date: {type: Date},  
slotsPerHour:{type: String},  
allAppointments :{ type: Array }  
},{ timestamps: true });    


module.exports = {
Appointment: AppointmentSchema
};


//appointment.js
let criteria = { "providerId": req.providerId,
     "date": req.date
    }
var res = await this.db.Appointment.findOne(criteria); // I want to save this response to different collection
console.log("res :"+res);    

await this.db.AppointmentLog.create(res);// here, I'm getting an error

// AppointmentLog-schema.js
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const AppointmentLogSchema = new Schema({
providerId: { type: String, index: true },
providerName: { type: String, index: true },
date: {type: Date},
slotsPerHour:{type: String},
allAppointments :{ type: Array }
},{ timestamps: true, strict : false });

module.exports = {
AppointmentLogSchema
};





/* console.log("res :"+res)
res :{ allAppointments:
[ { serialNo: 0, slots: [Array] },
{ hour: 1970-01-01T00:00:00.000Z, serialNo: 5, slots: [Array] } ],
_id: 5c30c82eb632745b14b20452,
providerId: 'D02AT029527F0374',
date: 2019-01-05T18:30:00.000Z,
providerName: 'Dr. Ray Smith',
createdAt: 2019-01-05T15:07:26.177Z,
updatedAt: 2019-01-06T06:38:31.215Z } */

在这里,我看不到文档的__v属性。之前我曾使用删除doc .__ v 来删除版本密钥。
下面是错误:

  

VersionError:未找到ID为“ 5c30c82eb632745b14b20452”版本0的匹配文档,其路径为“ allAppointments,_id,providerId,date,providerName,createdAt,updatedAt”

我不确定我是不是在做猫鼬不允许的错事,还是Mongo版本的问题(我正在使用3.6.9)。

0 个答案:

没有答案