Created
April 3, 2019 19:32
-
-
Save burningtree/680f1ccf37294c89589d82375941335c to your computer and use it in GitHub Desktop.
mongoose error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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