1
私のコレクションに挿入しようとしていますが、挿入しますが、サブ文書は保存されていません。マングースが子の文書を保存していません
私はこのスキーム/モデル持っている:私は、私が保存すると
import * as bodyParser from 'body-parser'
app.use(bodyParser.json())
app.post('/save/:type', async (req, res) => {
if (!req.xhr) res.sendStatus(400)
let p = new Person({
name: {
first: req.body.first,
last: req.body.last
},
dob: new Date()
})
p.save((err, data) => {
if (err) console.log(err);
else console.log('Saved : ', data);
})
res.sendStatus(200)
})
:私は、データを渡すと、そのようなモデルを使用することを明示使用しています
import { Schema, Document, Model, model } from 'mongoose'
export interface IPerson {
name: {
first: string
last: string
}
dob: Date
}
export interface IPersonModel extends IPerson, Document { }
let nameSchema: Schema = new Schema({
first: String,
last: String
})
let PersonName = model('PersonName', nameSchema)
export var personSchema: Schema = new Schema({
name: { child: PersonName.schema },
dob: Date
}, { timestamps: true })
export const Person: Model<IPersonModel> = model<IPersonModel>('Person', personSchema, 'people')
を端末に次の出力を取得します。
Saved : { __v: 0,
updatedAt: 2017-07-02T14:52:18.286Z,
createdAt: 2017-07-02T14:52:18.286Z,
dob: 2017-07-02T14:52:18.272Z,
_id: 595908a27de708401b107e4b
}
なぜ、私の子供name
は保存されないのですか?