These are chat archives for Automattic/mongoose

11th
Jan 2017
Lorenzo Gamboa García
@Lorengamboa
Jan 11 2017 11:00
@Lorengamboa
I dont understand the difference between static vs instance methods
in mongoose
any1 knows?
As far as I know, static ones are defined in the same model
but i dont understand what difference will make
Paul "Joey" Clark
@joeytwiddle
Jan 11 2017 11:48
@Lorengamboa In common terminology, instance methods are part of a particular document/object, and will be able to access that document's fields. But static methods are not associated with any particular document, only with the class, so they won't be able to access fields (unless they are passed a document when they are called).
Mohamed Nasrullah
@nasr18
Jan 11 2017 12:05
i have enabled auth in my mongodb. how do i execute query using mongoose with username and password?
Lorenzo Gamboa García
@Lorengamboa
Jan 11 2017 12:26
@joeytwiddle thanks
@joeytwiddle I think is most likely to use the static when I dont need to make make an instance of the model
methods seem to pretty fit with save queries
and static for retrieving data
Im I right?
Look at my repo model
what should I change?
Erinç Fırtına
@EricMcRay
Jan 11 2017 13:21
@Lorengamboa use statics instead of methods for statics model methods http://mongoosejs.com/docs/api.html#schema_Schema-static
Alex Munoz
@AlexMunoz
Jan 11 2017 13:43
i started to use node and mongodb, the connection should be static or create a new each time?
Erinç Fırtına
@EricMcRay
Jan 11 2017 13:44
@AlexMunoz should be static
Alex Munoz
@AlexMunoz
Jan 11 2017 13:46
so, the connection is never close ... singleton is the best way to do it?
Erinç Fırtına
@EricMcRay
Jan 11 2017 13:47
yeap
Alex Munoz
@AlexMunoz
Jan 11 2017 13:49
okay thanks ;)
Erinç Fırtına
@EricMcRay
Jan 11 2017 13:52
@AlexMunoz btw if you are using mongoose, it handles some connection stuff for you
Alex Munoz
@AlexMunoz
Jan 11 2017 14:24
@EricMcRay for example?
Erinç Fırtına
@EricMcRay
Jan 11 2017 14:38
connection pool, query queue ...
Ash
@abelmokadem
Jan 11 2017 14:51
Hi all, does anyone have experience with sorting an array of objects based on array of ids?
Using the mongodb query language
Erinç Fırtına
@EricMcRay
Jan 11 2017 14:53
@abelmokadem is this array field of an document?
Ash
@abelmokadem
Jan 11 2017 14:55
Yes @EricMcRay
Erinç Fırtına
@EricMcRay
Jan 11 2017 14:55
not possible
Ash
@abelmokadem
Jan 11 2017 14:56
@EricMcRay thx! That saves me time, I’ll go for a different implementation then
Erinç Fırtına
@EricMcRay
Jan 11 2017 14:57
if you want to always use that array in that order. you can get document sort that array at server-side and update with sorted new array
Ash
@abelmokadem
Jan 11 2017 14:58
Exactly what I’m doing now. Thanks :)
Lorenzo Gamboa García
@Lorengamboa
Jan 11 2017 22:14
Hello
i just cant figure out when to use static or instance methods
this is the model I made