我有非常大量的对象,需要导入到MongoDB中,但是我一次需要做一次,因此我可以使用mongoose-field-encryption加密静态的特定字段。
我能够使用mongoimport导入数据,然后能够使用Robo3T将其导出到JSON,但是当我尝试导入时会出现这些类型的错误。我仅以一个记录为例。
要导入的示例数据:
{
"_id" : { "$oid" : "5d82c8b95627367d122082cd" },
"clientID" : [ { "$oid" : "5d82240f7c8ddd03b62aee5e" } ],
"scheduled" : { "$date" : "2013-05-16T12:00:00.000+0000" },
"note" : "", "reminder" : false,
"cell" : false,
"type" : [ { "$oid" : "5d826362f4aac80a557348a2" } ],
"status" : [ { "$oid" : "5d82661cbc473c0a88826d09" } ],
"pmtdue" : 0.0,
"pmtduedate" : "",
"payment" : 0.0,
"pmttype" : "",
"paid" : false,
"pmtnote" : ""
}
我要导入的代码:
const appointment = new Appt(p).save();
错误:
ValidationError:Appt验证失败:
我了解需要了解我的架构才能理解该问题,所以这里是:
const apptSchema = new mongoose.Schema({
clientID: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Client'
},
status: {
type: mongoose.Schema.Types.ObjectId,
ref: 'ApptStatus'
},
type: {
type: mongoose.Schema.Types.ObjectId,
ref: 'ApptType'
},
scheduled: Date,
note: String,
cell: Boolean,
pmtdue: Number,
pmtduedate: Date,
payment: Number,
pmttype: String,
paid: Boolean,
pmtnote: String
});
我在做什么错?我的mongoose的package.json是:
"mongoose": "^5.7.1",