Я пытаюсь $set
с findOneAndUpdate
, но мои вложенные значения не устанавливаются должным образом.
Вот фрагмент моего SCHEMA :
...
courseMap: {
hasCourseMap: { type: Boolean, default: false },
parentMap: { type: Schema.Types.ObjectId, ref: "CourseMap" },
colleges: [
{
name: { type: String },
_id: { type: Schema.Types.ObjectId, ref: "College" }
}
],
title: { type: String },
ninth: {
hsCourses: [
{
courseName: { type: String, required: true },
courseNumber: { type: String, required: true },
_id: {
type: Schema.Types.ObjectId,
ref: "HighSchoolCourse",
autopopulate: true
}
}
],
collegeCourses: [
{
name: {
type: String,
required: true
},
courseNumber: { type: String, required: true },
description: { type: String },
courseCode: { type: String, required: true },
_id: {
type: Schema.Types.ObjectId,
ref: "CollegeCourse",
autopopulate: true
}
}
],
skills: []
},
tenth: {
hsCourses: [
{
courseName: { type: String, required: true },
courseNumber: { type: String, required: true },
_id: {
type: Schema.Types.ObjectId,
ref: "HighSchoolCourse",
autopopulate: true
}
}
],
collegeCourses: [
{
name: {
type: String,
required: true
},
courseNumber: { type: String, required: true },
description: { type: String },
courseCode: { type: String, required: true },
_id: {
type: Schema.Types.ObjectId,
ref: "CollegeCourse",
autopopulate: true
}
}
],
skills: []
},
eleventh: {
hsCourses: [
{
courseName: { type: String, required: true },
courseNumber: { type: String, required: true },
_id: {
type: Schema.Types.ObjectId,
ref: "HighSchoolCourse",
autopopulate: true
}
}
],
collegeCourses: [
{
name: {
type: String,
required: true
},
courseNumber: { type: String, required: true },
description: { type: String },
courseCode: { type: String, required: true },
_id: {
type: Schema.Types.ObjectId,
ref: "CollegeCourse",
autopopulate: true
}
}
],
skills: []
},
twelfth: {
hsCourses: [
{
courseName: { type: String, required: true },
courseNumber: { type: String, required: true },
_id: {
type: Schema.Types.ObjectId,
ref: "HighSchoolCourse",
autopopulate: true
}
}
],
collegeCourses: [
{
name: {
type: String,
required: true
},
courseNumber: { type: String, required: true },
description: { type: String },
courseCode: { type: String, required: true },
_id: {
type: Schema.Types.ObjectId,
ref: "CollegeCourse",
autopopulate: true
}
}
],
skills: []
},
year5: {
hsCourses: [
{
courseName: { type: String, required: true },
courseNumber: { type: String, required: true },
_id: {
type: Schema.Types.ObjectId,
ref: "HighSchoolCourse",
autopopulate: true
}
}
],
collegeCourses: [
{
name: {
type: String,
required: true
},
courseNumber: { type: String, required: true },
description: { type: String },
courseCode: { type: String, required: true },
_id: {
type: Schema.Types.ObjectId,
ref: "CollegeCourse",
autopopulate: true
}
}
],
skills: []
}
}
...
Вот мой update
объект:
{
"$set": {
"courseMap": {
"hasCourseMap": true,
"parentMap": "5e07fb5b40b723f03935cb31",
"colleges": [
{
"_id": "5dfee8128eacd562f0338678",
"name": "Eastfield"
},
{
"_id": "5e06a566559c3013687cc0f1",
"name": "University of North Texas at Dallas"
}
],
"ninth": {
"hsCourses": [
{
"_id": "5dfee4bb008dfb2fa4e89a43",
"abbr": "MATH",
"courseNumber": "7897987",
"courseName": "GEOMETRY",
"timestamp": "2019-12-22T03:36:27.026Z",
"__v": 0
}
],
"collegeCourses": [
{
"_id": "5dfef4d75581475988759efc",
"HSEquivCourses": [
"5dfee4bb008dfb2fa4e89a43"
],
"college": "5dfee8128eacd562f0338678",
"name": "test1",
"courseNumber": "test",
"description": "tesst",
"__v": 0
}
]
},
"tenth": {
"hsCourses": [
{
"_id": "5dfee4bb008dfb2fa4e89a43",
"abbr": "MATH",
"courseNumber": "7897987",
"courseName": "GEOMETRY",
"timestamp": "2019-12-22T03:36:27.026Z",
"__v": 0
}
],
"collegeCourses": [
{
"_id": "5e07dceb63b72fe4b74473e2",
"college": "5e06a566559c3013687cc0f1",
"name": "TEST",
"courseNumber": "tesat",
"description": "",
"courseCode": "test",
"__v": 0
}
]
},
"eleventh": {
"hsCourses": [
{
"_id": "5dfee4bb008dfb2fa4e89a43",
"abbr": "MATH",
"courseNumber": "7897987",
"courseName": "GEOMETRY",
"timestamp": "2019-12-22T03:36:27.026Z",
"__v": 0
}
],
"collegeCourses": [
{
"_id": "5dfef06ebe4ae31e7c6344bb",
"HSEquivCourses": [
"5dfee4bb008dfb2fa4e89a43"
],
"college": "5dfee8128eacd562f0338678",
"name": "Psychology",
"courseNumber": "1301",
"description": "test",
"__v": 0
}
]
},
"twelfth": {
"hsCourses": [
{
"_id": "5dfee4bb008dfb2fa4e89a43",
"abbr": "MATH",
"courseNumber": "7897987",
"courseName": "GEOMETRY",
"timestamp": "2019-12-22T03:36:27.026Z",
"__v": 0
}
],
"collegeCourses": [
{
"_id": "5e07dceb63b72fe4b74473e2",
"college": "5e06a566559c3013687cc0f1",
"name": "TEST",
"courseNumber": "tesat",
"description": "",
"courseCode": "test",
"__v": 0
}
]
},
"year5": {
"hsCourses": [
{
"_id": "5dfee4bb008dfb2fa4e89a43",
"abbr": "MATH",
"courseNumber": "7897987",
"courseName": "GEOMETRY",
"timestamp": "2019-12-22T03:36:27.026Z",
"__v": 0
}
],
"collegeCourses": [
{
"_id": "5dfef06ebe4ae31e7c6344bb",
"HSEquivCourses": [
"5dfee4bb008dfb2fa4e89a43"
],
"college": "5dfee8128eacd562f0338678",
"name": "Psychology",
"courseNumber": "1301",
"description": "test",
"__v": 0
}
]
}
}
}
}
И после использования StudentProfile.findOneAndUpdate({ _id: user.profile }, update)
Обновляется следующее: ключевые значения верхнего уровня, но мои вложенные значения не устанавливается.
"courseMap":{
"hasCourseMap" : true,
"parentMap" : ObjectId("5e07fb5b40b723f03935cb31"),
"colleges" : [
{
"_id" : ObjectId("5dfee8128eacd562f0338678"),
"name" : "Eastfield"
},
{
"_id" : ObjectId("5e06a566559c3013687cc0f1"),
"name" : "University of North Texas at Dallas"
}
],
"ninth" : {
"hsCourses" : [
{
}
],
"collegeCourses" : [
{
}
]
},
"tenth" : {
"hsCourses" : [
{
}
],
"collegeCourses" : [
{
}
]
},
"eleventh" : {
"hsCourses" : [
{
}
],
"collegeCourses" : [
{
}
]
},
"twelfth" : {
"hsCourses" : [
{
}
],
"collegeCourses" : [
{
}
]
},
"year5" : {
"hsCourses" : [
{
}
],
"collegeCourses" : [
{
}
]
}
}
Ниже приведен фрагмент документа до обновления:
...
"courseMap" : {
"hasCourseMap" : false,
}
...