0
я получаю следующее сообщение об ошибке при попытке проверить схему:Почему я получаю ошибку кастинга для следующей схемы mongooseJS?
"CastError: Cast к ObjectId не удалось для значения "{по: 58803a77479f7e2a2d069d93, по адресу: 2017-01-19T04: 03: 03.156Z}" на пути" _id»для модели "Poll"
const PollSchema = Schema({
title: {
type: String,
required: true
},
desc: {
type: String
},
created : {
by: {
type: Schema.Types.ObjectId,
ref: 'User'
},
at: {
type: Date,
default: Date.now
}
}
})
Вот код тестирования
describe('Associations',() => {
let _cindy, _poll;
beforeEach((done) => {
_cindy = new User ({
firstName : 'Cindy',
lastName : 'Cronkite'
})
_poll = new Poll ({
title : 'my first blog',
desc : 'yada yada yada'
created : {
by : _cindy._id
}
})
_poll.created = _cindy
_cindy.save()
.then(() => {
_poll.save().then(() => done())
})
})
it('saves a relation between a user and a poll', (done) => {
Poll.findOne({ title : 'my first blog'})
.populate('created')
.then((_pollQuery) => {
console.log('_pollQuery', _pollQuery)
assert(_pollQuery.created.by.firstName === 'Cindy')
done()
})
})
})
Это работает! спасибо – bresson