These are chat archives for Automattic/mongoose

3rd
Jun 2018
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 19:25
Hey
How do I throw a custom error when a model fails validation?
Omar
@iamyourabu
Jun 03 2018 20:29
hey there
is this chat frequently used?
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:29
I don't think so
Omar
@iamyourabu
Jun 03 2018 20:32
hmm I guess i'll ask my question just incase
i was wondering, how would someone reference a schema in another schema but like
not just the objectid
everything in the schema
like umm
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:33
ref:
Omar
@iamyourabu
Jun 03 2018 20:33
referencing a post to a user
so then i could do something like user.posts
or post.user.firstName
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:33
  createdBy: {
    type: ObjectId,
    ref: 'User',
    required: true,
  },
Omar
@iamyourabu
Jun 03 2018 20:33
yeah
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:33
like that
Omar
@iamyourabu
Jun 03 2018 20:33
but doesn't that only give the objectid?
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:33
then you do .populate('createdBy')
it does
but if you do populate it does that
Omar
@iamyourabu
Jun 03 2018 20:33
o
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:34
:P
Omar
@iamyourabu
Jun 03 2018 20:34
well what I did for this one thing is i have a Course schema and a teacher(user) schema
i just referenced the teacherId in the course schema
and then I would do a get request to look for all courses matching with the same teacher id as the logged in user :P
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:35
yeah
I understand
you might want to learn GraphQL
Omar
@iamyourabu
Jun 03 2018 20:36
eh it's kind of too late as i've already developed a lot with express/mongoose
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:37
Yeah I was in that situation too :P
when you get everything working, you might want to check it out
i'm kinda in the same situation
it's fine tho, don't feel pressured to put everything in graphql
but consider it for other projects/new versions for that :)
Omar
@iamyourabu
Jun 03 2018 20:38
does graphql handle referencing a lot easier than mongoose? :P
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:38
graphql does NOT replace mongoose
Omar
@iamyourabu
Jun 03 2018 20:38
oh?
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:38
graphql replaces.. REPL
Omar
@iamyourabu
Jun 03 2018 20:38
ahhh
just googled
seems like a lot to learn :P
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:40
Yeah, it is
it's kind of scary
then there's Prisma
which is kinda a mongoose replacement
I tried it and I wanted to cry
of how hard it is to make references, etc
Omar
@iamyourabu
Jun 03 2018 20:43
lol
i only like mongoose because of how simple it is
although i really wish referencing and other things were a lot
"nicer" to do
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:44
yeah
in HTTP APIs made with express it's sad af
Omar
@iamyourabu
Jun 03 2018 20:45
i assume i won't really run into a huge issue since my project will be used by my school and possibly more
but that's like
a lot of tudents lol
students*
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:45
loool i'm doing exactly the same
a homework manager
for my school
Omar
@iamyourabu
Jun 03 2018 20:45
ay nice im doing an automatic attendance thing with student cards
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:45
Nice
Omar
@iamyourabu
Jun 03 2018 20:46
student scans their cards by the door, marks them as present for the class and sends it to my backend and teachers can view attendance for each course
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:46
that's really cool
Omar
@iamyourabu
Jun 03 2018 20:47
will probably do a lot more like student card balance for the cafe or something
you got discord or something @v0idifier_twitter ?
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:48
Telegram?
I have discord but not active in it
Omar
@iamyourabu
Jun 03 2018 20:49
hmm i used to have telegram but haven't used it in a year lol
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:49
lol
Omar
@iamyourabu
Jun 03 2018 20:49
do you need like a phone # to add people or something?
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:50
Nope, you need to put your number to verify but don't need the num to add
Omar
@iamyourabu
Jun 03 2018 20:51
@v0idifier_twitter messaged u my username
vøid a.k.a. Machito Opresor
@v0idifier_twitter
Jun 03 2018 20:51
Done