-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (30 loc) · 975 Bytes
/
index.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 dbUrl = 'mongodb://fery:[email protected]:55587/idphoto'
const dbUrl = 'mongodb://fery:[email protected]:55587/idphoto'
mongoose.connect(dbUrl)
const db = mongoose.connection
db.once('open', () => {
console.log('connected')
})
const kittySchema = new mongoose.Schema({
name: String
})
kittySchema.methods.speak = function () {
const greeting = this.name ? 'Mewo name is ' + this.name : "I don't have a name"
console.log(greeting)
}
const Kitten = mongoose.model('Kitten', kittySchema)
// const fluffy = new Kitten({ name: 'fluffy1'})
// fluffy.save(function(err, fluffy) {
// if (err) return console.log(err)
// console.log(fluffy)
// fluffy.speak()
// })
// Kitten.findOne(function(err, kittens) {
// if (err) return console.log(err)
// console.log(kittens)
// })
Kitten.updateOne({name: 'fluffy'}, { name: 'kitty'},function(err, res) {
if (err) throw err
console.log(res)
})