These are chat archives for Automattic/mongoose

31st
May 2016
Sebastien Vaucouleur
@vaucouleur
May 31 2016 11:27
@bazineta Right, it is unique; we all agree I guess. So, the question is: why not declare it as such in the index definition ?
pdiogo
@PedroMD
May 31 2016 12:56
@bazineta thanks for the reply ;) upon giving this a proper thought, I came to the exact same conclusion as you did! thanks a lot :) currently working with UTC only on the server-side and storing the user's timezone (offset, basically - you're right) with momentjs so it can then be properly rendered using angular's date directive. this way, the client can easily toggle between local timezone and their browser's timezone and no other date is ever stored on the server.
Allan Bazinet
@bazineta
May 31 2016 12:58
@PedroMD I think any other way lies madness, really. We all need to move to stardate as soon as possible.
pdiogo
@PedroMD
May 31 2016 13:02
🖖
Yogesh Patel
@ycpatel813
May 31 2016 14:28
This message was deleted
pdiogo
@PedroMD
May 31 2016 14:29
are subdocs' automatically generated _ids also unique across all subdocs of any parent?
Yogesh Patel
@ycpatel813
May 31 2016 14:30
This message was deleted
pdiogo
@PedroMD
May 31 2016 14:32
I'm currently directly querying a nested doc's _id which is inside an array which is part of a subdocument. Should I also select the parent's _id, to be safe?
Yogesh Patel
@ycpatel813
May 31 2016 14:35
Hi User.findOne().or([criteria]) not working for me any alternative for it or am i doing wrong way?
Mohamed Nasrullah
@nasr18
May 31 2016 14:36
@PedroMD yeah u should
pdiogo
@PedroMD
May 31 2016 14:36
hm, ok. thanks!
will have to change some parts of my API as well then as I was not receiving the parents' _id
Mohamed Nasrullah
@nasr18
May 31 2016 14:39
without parentid u wont get that. are u???
pdiogo
@PedroMD
May 31 2016 14:39
i do. it works fine
BUT I'm not sure the generated _ids are really unique across all subdocs, so....
Mohamed Nasrullah
@nasr18
May 31 2016 14:40
_id's are unique.
pdiogo
@PedroMD
May 31 2016 14:47

i know they are, but I'm not sure they are under the child's scope only.

Practical example: parent.id(1).child.id(2) and parent.id(2).child.id(2) -> child.id(2) doesn't have an unique _id but it is a unique doc anyway as it was stored under a different parent's id and you could retrieve it anyway if you specify the parent's id. Understand what I mean? I just need to make sure this won't ever happen; otherwise, I will have to select the parent's id as well on every query

Allan Bazinet
@bazineta
May 31 2016 14:48
@PedroMD _ids are globally unique, as in, really, really unique. Precious little snowflakes, each one different. It warms my heart just to think of it.
pdiogo
@PedroMD
May 31 2016 14:48
good to know! should be quicker to query that id directly then :)
Allan Bazinet
@bazineta
May 31 2016 14:48
It usually is :)
Varun Jayaraman
@varunjayaraman
May 31 2016 15:51
any opinions on the best way to merge a POJO into a mongoose document? I have a custom merger function that recursively walks through the object and allows certain paths to be skipped (so that users cant overwrite admin-only/sensitive fields), but it's causing issues with subdocument arrays.
where the object being walked through is a POJO
LeonineKing1199
@LeonineKing1199
May 31 2016 17:04
Maybe consider a function like Ramda's merge.
Varun Jayaraman
@varunjayaraman
May 31 2016 17:04
similar to lodash merge?
LeonineKing1199
@LeonineKing1199
May 31 2016 17:08
Yes.
David Baldwynn
@whitef0x0
May 31 2016 21:10
What does a discriminator do?
is it like subclassing a schema or overwriting it?
btw are there any updated docs on mongoose? the ones on the site seem quite out of date