These are chat archives for Automattic/mongoose

28th
Jun 2018
Mihajlo Ilijić
@Pritilender
Jun 28 2018 09:06
Hey all. Quick question: Does Mongoose v4 supports getters and setters? I'm looking through the docs and I can't find anything. Google points me to v2.x docs when I try to Google "Mongoose getters and setters"...
Kev
@lineus
Jun 28 2018 09:16
yeah, this worked
#!/usr/bin/env node
'use strict';

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const schema = new Schema({
  name: {
    type: String,
    set: function(v) {
      return v.repeat(4);
    }
  }
});

const Test = mongoose.model('test', schema);

const test = new Test({
  name: 'yes'
});

console.log(test); //{ name: 'yesyesyesyes', _id: 5b34a73463f8d80c6ae24db0 }
on version 4.13.12
@Pritilender
Mihajlo Ilijić
@Pritilender
Jun 28 2018 09:21
@lineus thanks :) I'll have to investigate more why it's not working for me...
Kev
@lineus
Jun 28 2018 09:36
anytime! good to see you around @Pritilender :smile: let me know if I can help
Mihajlo Ilijić
@Pritilender
Jun 28 2018 09:38
Thanks :) My gitter is always on during work hours, but I don't have a lot of time to answer some of the questions people are asking :(