These are chat archives for Automattic/mongoose

Dec 2015
Theo Sherry
Dec 09 2015 02:33
@vkarpov15 How does a dependency injection framework address models not being able to compile more than once? If I want to mock a dependency differently for different tests, or have multiple dependencies, I can't recompile the model with these mocks.
Valeri Karpov
Dec 09 2015 15:03
With a DI framework you decouple the initialization of the model from your code, so you can initialize the model the same way, but using a different mongoose connection each time you need the model. Bottom line, overwriting require() in tests (or any other global state for that matter) is a bad anti-pattern - by definition, if your code uses require(), that require() call cannot be stubbed out. If you want the ability to stub something out, it should be a function parameter.
Christopher Shelley
Dec 09 2015 16:03
How does one A) generate a multikey index from the tags (array) attribute from every document in a collection and then B) return a list of each unique key from the index? thanks!
Christopher Shelley
Dec 09 2015 17:59
@vkarpov15 thanks a lot for your help, i was reading that earlier but wasn’t 100% sure