Skip to content

Instantly share code, notes, and snippets.

@lineus lineus/index.js
Last active Apr 6, 2018

What would you like to do?
arrow functions and mongoose (middleware, virtuals, getters/setters, and static/instance methods) don't mix
#!/usr/bin/env node
'use strict'
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const schema = new Schema({
name: String
schema.pre('save', (next) => {
console.log('arrow:', this)
schema.pre('save', function (next) {
console.log('common:', this)
const Test = mongoose.model('test', schema)
const test = new Test({ name: 'billy' }) => {
return mongoose.connection.close()
arrow: {}
common: { _id: 5ac734d3e57afb2595236f0e, name: 'billy' }
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.