PMXBOT Log file Viewer

Help | Karma | Search:

#mongodb logs for Saturday the 21st of November, 2020

(Back to #mongodb overview) (Back to channel listing) (Animate logs)
[08:10:46] <aimorris> I'm trying to get a random document from a collection in Node.js, and I'm doing that with db.collection('questions').aggregate([{ $sample: { size: 1 } }]); but it's just returning an AggregationCursor JSON object/
[08:10:55] <aimorris> How do I get the document
[08:39:48] <jindraj> d4rkp1r4t3: unfortunately I have to postpone indefinitely my 4.4.x test with turning off streaming replication
[12:37:24] <lootic> Hi! I am trying to to use aggregation pipelines. What I want to do is basically just find the document containing min and max for a field within every interval of N documents in a collection.
[15:29:46] <d4rkp1r4t3> lootic: might be good candidate for $bucket or $bucketAuto
[15:30:26] <d4rkp1r4t3> jindraj: that's a bummer. at least you are not stuck on 3.4.x right now like I am heh
[15:35:59] <jindraj> d4rkp1r4t3: what's holding you on 3.4.x? I'm trying to upgrade at least once a year. This time I upgraded sooner, I usually waits for later minor versions.
[15:54:35] <d4rkp1r4t3> code is using deprecated queries somewhere and breaks on 3.6.x. developers can never prioritize the upgrade because always building new features or fixing other things
[17:39:47] <lootic> d4rkp1r4t3 I've given $bucketAuto a try, I want it sorted on one field, but when there are few of that field I think that it would be good if it buckets dependendant on _id
[17:40:35] <lootic> example of something that almost looks right:
[17:40:42] <lootic> {
[17:40:42] <lootic> groupBy: "$year",
[17:40:43] <lootic> buckets: 50
[17:40:43] <lootic> }
[17:41:02] <lootic> can I make groupBy group by both $year and $_id somehow?
[17:41:19] <lootic> might be a dumb question but can't seem to find anything in doc regarding it
[18:03:20] <d4rkp1r4t3> you want to $bucketAuto only certain documents based on _id? you need a filter expression so you would add a $match stage before $bucketAuto. if your result set is dependant on the _id field which is generated by bucketAuto, you would want to include a filter expression after the $bucketAuto stage.
[18:12:07] <d4rkp1r4t3> maybe $sortByCount and filter on that result using your threshold for "few of that field"
[18:52:10] <lootic> hmm, not sure if that is exactly what I want, I thought id would be a good secondary grouping to ensure all buckets are of equal size
[18:52:22] <lootic> and that I get all the buckets I want
[18:58:17] <lootic> or hmm, I mean that I get an enough amount of buckets
[18:58:58] <lootic> what I basically want to achieve is the ability to get the shape of a plot when there are more datapoints than there are pixels
[18:59:22] <lootic> and for that I want to get the min and max for a certain field in every given interval
[19:00:15] <lootic> and then also maintain the order of the min and max