PMXBOT Log file Viewer

Help | Karma | Search:

#mongodb logs for Monday the 5th of April, 2021

(Back to #mongodb overview) (Back to channel listing) (Animate logs)
[14:41:08] <pagios> hello, is there a way to return the elemented in an array to be sorted by date from oldest to newest?
[14:41:44] <pagios> i am already returning documents sorted by date, but each doc has also an array and inside that array i have dates too that i would like to sort too
[15:12:15] <VectorX> pagios you may need to use unwind, https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/
[15:13:45] <pagios> VectorX: hello, i tried did db.events.find({_id:3}).sort({ "content.date" : 1 } ) doesnt sort by date
[15:14:24] <pagios> VectorX: can i add to the beginning of an array when i push to an array ?
[15:14:30] <pagios> prepend
[15:16:15] <VectorX> you would have to use aggregate and not find, then unwind the inner array and sort it
[15:17:59] <VectorX> there is an example here https://stackoverflow.com/questions/15388127/mongodb-sort-inner-array
[15:18:12] <pagios> i am thinking of #$push and $position
[15:19:52] <VectorX> wouldnt that just complicate the situation?
[15:21:27] <VectorX> you wouldnt know the order anyway, and if you are writing items to the array chronological, your list would automatically be sorted in ascending order
[15:21:30] <VectorX> by date
[15:22:39] <pagios> VectorX: i am mainly writing a timeline, and want newet comment to be on first element in array
[15:23:00] <pagios> since comments are pushed by current date i think i can use push and position 0
[15:23:42] <pagios> i take current date from nodejs and insert that into mongo
[15:24:21] <VectorX> hmm, writing comments into an array of a doc doesnt seem like a good idea
[15:24:38] <VectorX> unless you are certain it wont go over 16mb
[15:25:31] <pagios> yes its max 20 comments or so
[15:25:41] <pagios> its annoucments mainly not comments
[15:32:31] <VectorX> pagios you can try your suggetion and see what the results look like, I have not tried it myself so cant comment on the pitfall
[15:32:36] <VectorX> s
[15:33:00] <pagios> thank you for your time VectorX