These are chat archives for Automattic/mongoose

13th
Mar 2018
Chris Hurst
@ytsruh
Mar 13 2018 04:31
@mettjus I might (probably am) misinterpreting your issue but would this not best be solved via a many-to-many relationship within the documents?
Ghost
@ghost~5928d90bd73408ce4f629b9e
Mar 13 2018 04:45
MONGOOSE SUCKS
Chris Hurst
@ytsruh
Mar 13 2018 04:46
hahaha those trolls
Ghost
@ghost~5928d90bd73408ce4f629b9e
Mar 13 2018 04:51
lEt'S fAcE iT, wRiTinG MoNgoDB vAliDatioN, cAstinG aNd bUsiNeSs loGiC bOilerPlAte is a drAg. tHat's wHy we wrRotE MoNgoOsE.
Chris Hurst
@ytsruh
Mar 13 2018 04:58
tRoLL
Kev
@lineus
Mar 13 2018 10:00
what's up Chris?
Chris Hurst
@ytsruh
Mar 13 2018 10:00
@lineus nothing, just enjoying another sandy day in dubai
Kev
@lineus
Mar 13 2018 10:01
I miss the desert.
I grew up in the southwest part of the US
now I live in a snowy tundra hellscape
never marry a girl from the midwestern US :)
Chris Hurst
@ytsruh
Mar 13 2018 10:05
sounds awful haha
there are too many jokes to make there haha
Kev
@lineus
Mar 13 2018 10:05
heh, trust me, I KNOW.
Chris Hurst
@ytsruh
Mar 13 2018 10:09
do you work for automattic?
curious as to how you got so involved in the mongoose project
Kev
@lineus
Mar 13 2018 10:13
I wish I had a better answer, but mongodb just fascinates me. I've wanted to contribute to an open source project since I was a sysadmin back in the day. So when I started playing with node and javascript a few months back, I stumbled on mongoose , and decided to jump in with both feet.
Chris Hurst
@ytsruh
Mar 13 2018 10:13
its a great answer
i had the same with keystonejs, but it seems the project has gone quiet again now
Kev
@lineus
Mar 13 2018 10:14
I took a 4 year hiatus from working in tech, so I'm also brushing up on my old skill set while learning a new one.
Chris Hurst
@ytsruh
Mar 13 2018 10:14
nice
still a sysadmin?
Kev
@lineus
Mar 13 2018 10:17
no, I haven't felt the confidence to actually look someone in the eye and say 'hire me' yet. I'm getting close though.
Mihajlo Ilijić
@Pritilender
Mar 13 2018 10:17
@ytsruh any special reason to use keystone? I'm maintaining a project in keystone and hate it every day... it's so... hacky for some normal things
Kev
@lineus
Mar 13 2018 10:20
I hadn't actually heard of keystone before, was just looking it up :)
Mihajlo Ilijić
@Pritilender
Mar 13 2018 10:21
It's nice that you have admin UI generated for you, but that UI becomes useless at some point. It's useless unless you want to copy keystone out of node_modules and edit the templates by yourself, which is a no-no for me...
And sorry for venting out...
Chris Hurst
@ytsruh
Mar 13 2018 10:41
@Pritilender haha no worries. No i agree, its great for small projects but it needs to be extensible for it to be used on bigger/enterprise grade stuff
Mihajlo Ilijić
@Pritilender
Mar 13 2018 10:47
Yup...
Chris Hurst
@ytsruh
Mar 13 2018 10:55
@Pritilender its worht looking at connextcms.com though, its a promising extension
Mihajlo Ilijić
@Pritilender
Mar 13 2018 11:02
Hm... Looks interesting. I'l definetly take a look soon :)
Johnny Wu
@wxs77577
Mar 13 2018 13:12
hi, I store a user's id in user_id,and I can populate the user to user_id but I wanna keep
user_id as the raw id and populate the user to another VIRTUAL fielf
field like 'user', how can I do that?
Ghost
@ghost~5928d90bd73408ce4f629b9e
Mar 13 2018 13:57
i love mongoose
hillct
@hillct
Mar 13 2018 21:07
Good afternoon all. Is there a way, within a model definition, to indicate that if, when a model is updated and a field contains no value, that field should be set to no value ie: ‘’ rather than rataining the value it hads before the update? Typically, I’d do this in the controller, ie: newValue || ‘’; but is there a way to embed that logic in the schema definition?
Kev
@lineus
Mar 13 2018 22:34
hey @hillct
you mean when you do something like this?
#!/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: 'Jimi'
})

test.save((err, doc) => {
  if (err) { return console.error(err) }
  Test.findByIdAndUpdate(doc._id, { name: '' }, (err, noname) => {
    if (err) { return console.error(err) }
    mongoose.connection.close()
    return console.log(noname)
  })
})
outputs something like this:
$ ./hillct.js 
{ _id: 5aa85236851de56b65080510, name: 'Jimi', __v: 0 }
$