These are chat archives for Automattic/mongoose

13th
Jul 2016
Matt Huijsse
@mistamadd001
Jul 13 2016 08:00
hey guys, quick noob question is this the right way to create a one option required???
    phone: {
        mobile: Number,
        home: Number,
        work: Number,
        required: true
    },
ryxo
@ryxo
Jul 13 2016 09:05
noob question:
How I can get a collection of database created without mongoose ?
Marko Bolliger
@cannap
Jul 13 2016 09:48
@ryxo can you not just create a Schema
with the same naem
name
Alex Shpak
@ishikawayoshi
Jul 13 2016 09:49
@cannap sry, can't catch you problem, could you explain
Marko Bolliger
@cannap
Jul 13 2016 09:49
yea no problem
my solutions works but not sure its the right way
Matt Huijsse
@mistamadd001
Jul 13 2016 09:51
anyone got any ideas on my issue? is it even possible inside the model?
Alex Shpak
@ishikawayoshi
Jul 13 2016 09:52
so i search hundreds blogs tutorials documentation not find any better ways yet, if you find it please let me know @cannap
Marko Bolliger
@cannap
Jul 13 2016 09:52
for what
Alex Shpak
@ishikawayoshi
Jul 13 2016 09:52
@mistamadd001 required for what field?
Marko Bolliger
@cannap
Jul 13 2016 09:52
for my problem updating multipe _ids with increase the order number?
Alex Shpak
@ishikawayoshi
Jul 13 2016 09:52
@cannap yep
Marko Bolliger
@cannap
Jul 13 2016 09:53
has _ids a fixed order in mongo?
Matt Huijsse
@mistamadd001
Jul 13 2016 09:54
@ishikawayoshi any of the 3, im trying to get it so the new user has to give at least one contact number
Matt Huijsse
@mistamadd001
Jul 13 2016 09:59
@ishikawayoshi do you understand my meaning?
Alex Shpak
@ishikawayoshi
Jul 13 2016 10:01

@mistamadd001

phone: {
        mobile:{type: Number},
        home: {type: Number},
        work: {type: Number,required:true}
    }

i think you can do it this way but i need to test it

Matt Huijsse
@mistamadd001
Jul 13 2016 10:02
that would make only the work number required, Im not specifying which number is required, just that i must have one of them
Marko Bolliger
@cannap
Jul 13 2016 12:33
Hi, will the pre('remove') middleware just fire when the doc has no error when i remove or?
because i cant find a after('remove') or something
Alexander Dzhoganov
@AlexanderDzhoganov
Jul 13 2016 12:58
Hello, I want to overwrite an existing model's schema but it seems mongoose explicitly forbids it with an OverwriteModelError exception. Is there a technical reason why it wouldn't work?
I found where the check is and I'm going to try to comment it out and see what happens but I don't want to bet my data on it without confirmation
Dang Hong Thanh
@danghongthanh
Jul 13 2016 16:07
when i do logging on my mongoDB, i saw this error on the error log:
[conn360] DBException thrown :: caused by :: 112 WriteConflict
and other error log is: DBException thrown :: caused by :: 9001 socket exception [CLOSED]
does anyone face this issue before?
Pier-Luc Gagnon
@Nepoxx
Jul 13 2016 18:43
is there a way to use .findOneAndUpdate() and know whether an update occured or an upsert?
LeonineKing1199
@LeonineKing1199
Jul 13 2016 19:47
I think it returns the original document by default so maybe the callback will be passed an undefined or null document.
So you'd know you have an upsert if the original is falsey
Pier-Luc Gagnon
@Nepoxx
Jul 13 2016 19:56
Yeah, that's what I saw, but then I won't have the newly inserted document's id. I don't think this is possible because mongo's findAndModify either returns the "old" document (or null), or the new one, nothing else.
LeonineKing1199
@LeonineKing1199
Jul 13 2016 19:59
Oh, and you'd want the new id but also to know if it was upserted
Oh man, that's a tough cookie
I know you can set a flag to get the raw Mongo response
Would that maybe contain relevant info?
Pier-Luc Gagnon
@Nepoxx
Jul 13 2016 20:00
I'm creating a player document, and if it's a new player, I want to do some bookeeping (create an empty gameState document, etc.), I'm doing it the ol' fashioned way: findOne on the User, if null, create the User and perform the new player book keeping
AFAIK mongo's raw response for findAndModify is exactly the same as Mongoose's, i.e. simply not possible
LeonineKing1199
@LeonineKing1199
Jul 13 2016 20:01
Yeah, sometimes there just isn't really a better way than the straight-forward "dumb" way.
Would be nice though if the response from findAndModify contained more info though.
Pier-Luc Gagnon
@Nepoxx
Jul 13 2016 20:05
It's not such a huge deal when the DB is "close", but when it's remote like DynamoDB or whatnot, the RTT is more considerable
(It'll be my first time using Mongo in production so I am considering switching to Dynamo or Google's equivalent because I know I'll mess something up with sharding/replication or whatnot)
LeonineKing1199
@LeonineKing1199
Jul 13 2016 20:08
Yeah, I never got the appeal of replication because (the little that I read about) only one instance of the DB received writes.
Kind of defeats the point if you're still throttled through one db
I guess it's nice to have back-ups though.