-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdiscriminator-test.js
39 lines (37 loc) · 1.01 KB
/
discriminator-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const mongoose = require('mongoose')
const { Animal, Cat, Dog } = require('./database/animal')
const casual = require('casual')
function fetchDogs (numberOfItems) {
return [...new Array(numberOfItems)].map((_, index) => ({
name: casual.name,
woofPower: casual.integer(0, 100)
}))
}
(async () => {
try {
await mongoose.connect('mongodb://localhost:27017/animals', {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true
})
await Animal.deleteMany({})
const dogs = fetchDogs(2)
console.log({ dogs })
await new Dog({
name: casual.name,
woofPower: casual.integer(0, 100)
}).save()
// await Dog.findOneAndUpdate({ name: 'lol' }, dogs[0], { upsert: true, new: true }).lean()
await Dog.bulkWrite(dogs.map(dog => ({
updateOne: {
filter: { name: dog.name },
update: { $set: dog },
upsert: true
}
})))
process.exit(0)
} catch (err) {
console.error(err)
}
})()