These are chat archives for Automattic/mongoose

24th
Sep 2015
Vinothbabu
@vinothbabu
Sep 24 2015 01:32
Yes it would
Collection - plural Schema/model - Singular
Ven Korolev
@ErrorPro
Sep 24 2015 03:58
This message was deleted
Aram Bayadyan
@aramix
Sep 24 2015 07:59
@vinothabu Thanks, is there some conversion too if the collection name is in camelCase?
kanedauy
@kanedauy
Sep 24 2015 14:10
Helo
What is the latest stable version of mongoose, to add in a proy of node.js package.json
?
Valeri Karpov
@vkarpov15
Sep 24 2015 14:31
@aramix just be careful about case - mongoose lowercases when pluralizing by default. You can always specify the collection name manually though, db.model('Category', schema, 'Categories');
back in 2012 I once lost about an hour at a hackathon because I couldn't figure out why mongoose wasn't inserting anything into the expected collection - I was expecting first name upper case :)
and the rule is that mongoose calls .toLowerCase() before pluralizing: https://github.com/Automattic/mongoose/blob/master/lib/utils.js#L27
@kanedauy 4.1.8
kanedauy
@kanedauy
Sep 24 2015 14:46
thanks a lot, so 4.1.8 is stable
Juan Pablo
@jotapdiez
Sep 24 2015 15:04
hi all! I have a question about Javascript field types
is there any way to handle (save and retrieve) db.system.js?
Valeri Karpov
@vkarpov15
Sep 24 2015 16:52
@kanedauy what makes you think its unstable?
@jotapdiez stuff in db.system.js is usually just a string, but can also be an object with a string property
although I wouldn't recommend using db.system.js, that's a bit of a dark corner
James Lee
@uptownhr
Sep 24 2015 17:00
@vkarpov15 node question, how does mongoose keep a singleton?
the mongoose.connect, and the models are connected to one connection pool
how does all the models, keep track the connection?
Aram Bayadyan
@aramix
Sep 24 2015 17:53
@vkarpov15 unfortunately I have already lost a day on that, finally just specified the collection name explicitely and that worked. Thanks though, I didn't know it was lowercasing collection names. Sometimes all those fancy features make life harder )))) anyways))
Aram Bayadyan
@aramix
Sep 24 2015 18:03
@vkarpov15 I see it's also possible to tell the mongoose to stop pluralizing by setting the pluralization option to false instead of specifying collection names for each schema))
Samuel Hagman
@samhagman
Sep 24 2015 18:37
Hey quick question because I don't see it in the Docs, can you specify which fields to return when doing a .findOneAndUpdate() call?
Or does it always just return to you the full document?
This made it seem like it was possible but the documentation it points to does not show that select is an available option.
Valeri Karpov
@vkarpov15
Sep 24 2015 18:40
@aramix that's true. I typically just prefer to set the collection name explicitly to prevent any mixups
@uptownhr Model.db is the connection used to create the model
@samhagman MyModel.findOneAndUpdate({}, { a: 1 }, { projection: { a: 1 } }); should work
where 'projection' is a map of fields to select
unfortunately this doesn't support mongoose's string syntax just yet
I opened up an issue Automattic/mongoose#3403 for that
Samuel Hagman
@samhagman
Sep 24 2015 18:50
Thank you @vkarpov15 that should really be in the docs
Valeri Karpov
@vkarpov15
Sep 24 2015 21:27
you're entirely right, it should. Will make sure to add that to the ticket.
James Lee
@uptownhr
Sep 24 2015 22:41
@vkarpov15 i guess my question is, how is Model.db a singleton
how does Model know where to get the db connection from?
James Lee
@uptownhr
Sep 24 2015 22:46
what does mongoose.connect register for mongoose.model to know that there is a connection
i'm seeing that a new Mongoose object is always being instantiated.
mostly likely i'm just not understanding something but I really wish i understood :)