Skip to content

Instantly share code, notes, and snippets.

@burningtree
Created April 3, 2019 19:32
Show Gist options
  • Select an option

  • Save burningtree/680f1ccf37294c89589d82375941335c to your computer and use it in GitHub Desktop.

Select an option

Save burningtree/680f1ccf37294c89589d82375941335c to your computer and use it in GitHub Desktop.
mongoose error
const mongoose = require('mongoose')
const Period = new mongoose.Schema({
start: Date,
end: Date
}, { _id: false })
const Cat = mongoose.model('Cat', {
name: String,
period: Period
})
async function test() {
const db = await mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true})
const period1 = {
start: new Date('2018-01-01T10:00Z'),
end: new Date('2018-01-01T15:00Z')
}
const kitty = new Cat({ name: 'Zildjian', period: period1 })
console.log(kitty.toJSON())
const period2 = {
start: new Date('2018-01-02T15:00Z'),
end: new Date('2018-01-02T20:00Z')
}
kitty.period = period2
console.log(kitty.toJSON())
await db.disconnect()
}
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment