These are chat archives for Automattic/mongoose

26th
Apr 2016
AngryDrunkard
@AngryDrunkard
Apr 26 2016 03:12 UTC
Hi, I'm pretty new to javascript/node/mongoose etc. So I'm sure I'm doing something wrong. Anyhow I've been playing around with ajax and storing and retrieving a json object with some number 4 digits with a 2 digit decimal place. I've noticed that when retrieving my object the server response shows what exactly what is in my object. When I view the object in mongo I see the 4 digit numbers with 2 digit decimal places, but when I access them or I if I dump the ajax response to the console it's dropping everything to the right of the decimal place. Is that normal? Should I be doing something differently?
Herpiko Dwi Aguno
@herpiko
Apr 26 2016 05:33 UTC
Hi, I've been playing with mongoose aggregate and the result was matched with my expectation and given in a GET response.
Then I updated the original colection and rerun the aggregation from HTTP GET
But, the result is same as before I updated the collection.
I've to restart the apps, fetch again and now the aggregation result updated as well as the collection.
Is ther anyway to fetch the updated aggregation result without restarting the apps?
Christoph Werner
@codepunkt
Apr 26 2016 07:36 UTC
@vladotesanovic var instance = new Model() is a model constructor. i can call that without a parameter and it defaults the parameter to empty object {}
Vlado Tesanovic
@vladotesanovic
Apr 26 2016 07:38 UTC
@gonsfx yes and that is instance of new model
Valeri Karpov
@vkarpov15
Apr 26 2016 20:47 UTC
@herpiko mongoose doesn't cache aggregation results in any way. Perhaps your HTTP client is caching the result?
@AngryDrunkard code samples please. Describing code in English is very hard.
Vlado Tesanovic
@vladotesanovic
Apr 26 2016 20:49 UTC
@vkarpov15 Hey, when you are here, can i ask you something? Broad question.
Valeri Karpov
@vkarpov15
Apr 26 2016 20:50 UTC
@arozwalak I'd recommend using $unwind when you're dealing with arrays like that, so unwind the projects array, count the tasks, then $group back together
@vladotesanovic yep
Vlado Tesanovic
@vladotesanovic
Apr 26 2016 20:52 UTC
MongoDB ( as well as Mongoose ) approach is to store everything in one collection? You have .populate() function, but again, storing things in one collection is better than having many collections?
Is it good approach ( if previous statement is true ) to store one million documents in one collection ( or more than that )? And to query that collection ( covered queries of course )? @vkarpov15
Valeri Karpov
@vkarpov15
Apr 26 2016 20:53 UTC
Not necessarily, the ideal is to store everything you want to query for in one collection and use $lookup sparingly when necessary :)
and nothing wrong with storing a million or more docs in one collection, just make sure you have indexes in place otherwise queries will have to scan every document
Vlado Tesanovic
@vladotesanovic
Apr 26 2016 20:54 UTC
@vkarpov15 $lookup is introduced in 3.2 if i am not wrong
Valeri Karpov
@vkarpov15
Apr 26 2016 20:54 UTC
yep
Vlado Tesanovic
@vladotesanovic
Apr 26 2016 20:55 UTC
@vkarpov15 What you think about steaming data trough web sockets?
Valeri Karpov
@vkarpov15
Apr 26 2016 20:55 UTC
actually my first statement was probably not the most accurate. Say you're storing users and you want to sort users by the number of events they've hosted - store the number of events the user has hosted in the user doc
web sockets are super cool :)
Vlado Tesanovic
@vladotesanovic
Apr 26 2016 20:56 UTC
ok, i have few collections, i am not mixing things
Valeri Karpov
@vkarpov15
Apr 26 2016 20:57 UTC
I guess the general point I'm trying to get at is "store all the data you want to execute transactional queries on with the document itself rather than relying on joins + denormalization"
Vlado Tesanovic
@vladotesanovic
Apr 26 2016 20:57 UTC
yes, i want to get advantage of stream() mongoose function
Valeri Karpov
@vkarpov15
Apr 26 2016 20:57 UTC
yeah stream is quite useful
Vlado Tesanovic
@vladotesanovic
Apr 26 2016 20:57 UTC
and to send huge data to client with web sockets
Valeri Karpov
@vkarpov15
Apr 26 2016 20:57 UTC
just make sure the client isn't accidentally aggregating all the data :)
Vlado Tesanovic
@vladotesanovic
Apr 26 2016 20:58 UTC
that can be bad experience if you have 2 GB of ram memory :)
Valeri Karpov
@vkarpov15
Apr 26 2016 20:59 UTC
err rather hanging on to all the data. You can definitely send 1GB of data over a web socket over a period of time, but if client isn't GC-ing then you'll run out of memory pretty quickly
and Chrome's "he's dead, jim" page is terrible UX :)
Vlado Tesanovic
@vladotesanovic
Apr 26 2016 20:59 UTC
i was testing few days ago, in that test, i send 100 000 documents to client and load it with simple angularjs applicatin
in first few seconds, Chrome consumed over 1 GB
but after GC, it was like 200-300 MB
Valeri Karpov
@vkarpov15
Apr 26 2016 21:01 UTC
:+1:
Vlado Tesanovic
@vladotesanovic
Apr 26 2016 21:02 UTC
One more question :) @vkarpov15 lean() should give better performance than to go without it