Skip to content

Instantly share code, notes, and snippets.

@lineus lineus/irfaan.js Secret
Created Mar 22, 2018

Embed
What would you like to do?
use .update() query builder method
#!/usr/bin/env node
'use strict'
const mongoose = require('mongoose')
mongoose.connect('mongodb://localhost/test')
const Schema = mongoose.Schema
const schema = new Schema({
name: String
})
const Test = mongoose.model('test', schema)
const test = new Test({
name: 'Jimmy Hendrix'
})
async function run () {
await Test.remove({})
await Test.create(test)
await Test.findOne({ _id: test._id })
.update({ name: 'Jimi Hendrix' })
let doc = await Test.findOne({ _id: test._id })
console.log(doc.name)
return mongoose.connection.close()
}
run()
gitter: ./irfaan.js
Jimi Hendrix
gitter:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.