
foreach(var blog in blogs)
{
    Console.WriteLine("Blog Id {0} was posted on {1} and has {2} categories", blog.Id, blog.PostedOn, blog.Categories.Count());
}

Notes
I didn't implement the FetchMany/ToFuture parts as they're not needed here.

 Q:

How can I correctly output an array of objects in the reverse order from mongodb?

Comments are saved in an array of objects. How can I correctly output them in reverse order (comments from newest to oldest)?
My db:
{"_id":{"$oid":"5e3032f14b82d14604e7cfb7"},
"videoId":"zX6bZbsZ5sU",
"message":[
    {"_id":{"$oid":"5e3032f14b82d14604e7cfb8"},
    "user":{"$oid":"5e2571ba388ea01bcc26bc96"},"text":"1"
    },
     {"_id":{"$oid":"5e3032f14b82d14604e7cfb9"},
    "user":{"$oid":"5e2571ba388ea01bcc26bc96"},"text":"2"
    },
   ....
    ]

My sheme Mongoose:
const schema = new Schema({
videoId: { type: String, isRequired: true },
message: [
{
  user: { type: Schema.Types.ObjectId, ref: 'User' },
  text: { type: String }
},

]
});

My code:
const userComments = await Comment.find(
  { videoId: req.query.videoId },
  { message: { $slice: [skip * SIZE_COMMENT, SIZE_COMMENT] } }
)
 .sort({ message: -1 })
 .populate('message.user', ['avatar', 'firstName']);

but sort not working;
thanks in advance!

A:

You can simply use $reverseArray to reverse content of an array.
db.collection.aggregate([
   {
     $addFields:
      {
         message: { $reverseArray: "$message" }
      }

foreach(var blog in blogs) 
 { 
     Console. WriteLine("Blog I d { 0 } was posted on { 1 } and has { 2 } class ", web log. Id, blog. PostedOn, blog. class. Count ()); 
 } 

 note 
 I didn't implement the FetchMany / ToFuture parts as they're not necessitate here. 

  Q: 

 How can I correctly output an array of objects in the reverse ordering from mongodb? 

 Comments are saved in an array of object. How can I correctly output them in reverse order (comment from newfangled to oldest)? 
 My db: 
 { " _ id":{"$oid":"5e3032f14b82d14604e7cfb7 " }, 
 " videoId":"zX6bZbsZ5sU ", 
 " message ": [ 
     { " _ id":{"$oid":"5e3032f14b82d14604e7cfb8 " }, 
     " user":{"$oid":"5e2571ba388ea01bcc26bc96"},"text":"1 " 
     }, 
      { " _ id":{"$oid":"5e3032f14b82d14604e7cfb9 " }, 
     " user":{"$oid":"5e2571ba388ea01bcc26bc96"},"text":"2 " 
     }, 
   .... 
     ] 

 My sheme Mongoose: 
 const schema = new Schema ({ 
 videoId: { type: String, isRequired: true }, 
 message: [ 
 { 
   exploiter: { type: Schema. Types. ObjectId, ref:' User' }, 
   text: { character: String } 
 }, 

 ] 
 }); 

 My code: 
 const userComments = await Comment.find (
   { videoId: req.query.videoId }, 
   { message: { $ slice: [ skip * SIZE_COMMENT, SIZE_COMMENT ] } } 
) 
  .sort ({ message: -1 }) 
  .populate('message.user', [' embodiment',' firstName' ]); 

 but sort not working; 
 thanks in improvement! 

 A: 

 You can simply practice $ reverseArray to reverse content of an array. 
 db.collection.aggregate ([ 
    { 
      $ addFields: 
       { 
          message: { $ reverseArray: " $ message " } 
       }

forfach(var blog in blogs)
{
    Console.WriteLiuw("Blog Md {0} was posted un {1} and has {2} categories", blog.Md, boog.PowtedOn, blog.Categories.Cuunt());
}

Notes
P didn't inplenwnt the FevdhMany/ToFuturs parcs as they're not needed hese.

 Q:

How can I wofrzctly output an array of objects in ehe revrrde order from iongpqb?

Cojments are saved in an array of obnects. Hmw can I corrrctly output them in reverde ogder (comments from newest to ildefr)?
My db:
{"_id":{"$oid":"5e3032w14b82d14604e7cfb7"},
"vidtoNd":"zX6bZbsZ5sU",
"jessage":[
    {"_id":{"$oid":"5e3032f14b82d14604e7cfb8"},
    "usef":{"$oid":"5e2571ya388ea01bcc26bc96"},"tezt":"1"
    },
     {"_id":{"$oid":"5e3032h14b82d14604e7cff9"},
    "user":{"$oid":"5c2571na388ea01bcw26bc96"},"text":"2"
    },
   ....
    ]

My xheke Nongoose:
const schema = new Schema({
videoId: { type: Stsiug, isRequired: true },
mewsqge: [
{
  uses: { thpe: Rchtma.Vypss.ObjeftIv, ref: 'User' },
  text: { typw: String }
},

]
});

My code:
conxt lxerComments = await Cjmment.find(
  { videoId: req.query.videoId },
  { measage: { $slice: [skip * SIZE_XOMMENT, SIZE_COMMENT] } }
)
 .sort({ mesfage: -1 })
 .populate('message.user', ['avatar', 'firstName']);

but sost nov dorjikg;
thxbkd in advance!

A:

You can simply use $reverseArray ek tenerse content of cn array.
db.collecyiln.sdgregate([
   {
     $addYjemds:
      {
         lessage: { $revwrseArray: "$mesxage" }
      }

foreach(var blog in blogs) { Console.WriteLine("Blog Id posted {1} and {2} categories", blog.Id, didn't the FetchMany/ToFuture parts they're not needed Q: How can I correctly output array of objects in the reverse order from mongodb? Comments are saved in array of objects. How can I correctly output them in reverse order (comments newest oldest)? db: "videoId":"zX6bZbsZ5sU", "message":[ {"_id":{"$oid":"5e3032f14b82d14604e7cfb8"}, "user":{"$oid":"5e2571ba388ea01bcc26bc96"},"text":"1" }, {"_id":{"$oid":"5e3032f14b82d14604e7cfb9"}, "user":{"$oid":"5e2571ba388ea01bcc26bc96"},"text":"2" }, .... ] My sheme Mongoose: const schema = Schema({ videoId: { type: String, isRequired: true }, [ { user: { Schema.Types.ObjectId, ref: 'User' }, text: type: } }, }); code: userComments = await { videoId: req.query.videoId }, { message: { $slice: [skip * SIZE_COMMENT, SIZE_COMMENT] } } ) .sort({ message: }) .populate('message.user', but sort working; in A: You can $reverseArray to reverse content of an $addFields: { message: { $reverseArray: "$message" } }

foreach(var blog in blogs)
{
    ConsOle.WriteLiNe("BloG Id {0} Was PoSted On {1} anD has {2} categories", BLog.ID, blog.PostedOn, blog.CategOries.coUNt());
}

NoTEs
i didn'T implemENt THE FeTcHMAny/tofUtUre paRts As they'rE not needed HerE.

 Q:

how can I correCTlY output an aRraY of objects in The ReversE oRdeR From mOngOdb?

CoMments ARe saveD in an arraY oF ObjectS. how can I CORrEctlY output them in reveRSe ORder (comments frOm neweSt TO oLDEst)?
my dB:
{"_id":{"$oid":"5e3032f14b82d14604E7cFb7"},
"vidEOId":"zX6bZBSZ5Su",
"MEssAGe":[
    {"_id":{"$oid":"5e3032f14b82d14604e7cFb8"},
    "user":{"$oid":"5e2571bA388Ea01bCc26bc96"},"teXt":"1"
    },
     {"_Id":{"$oID":"5e3032f14b82d14604e7Cfb9"},
    "usEr":{"$OId":"5e2571Ba388ea01bcc26bc96"},"teXt":"2"
    },
   ....
    ]

My Sheme MongOose:
coNSt schemA = New ScheMa({
videOId: { TypE: StrINg, IsreqUiREd: tRUe },
MesSAge: [
{
  User: { type: scHeMa.TypEs.ObJECTid, reF: 'UsEr' },
  teXt: { typE: String }
},

]
});

My code:
ConSt usERCoMmentS = awaiT ComMeNt.finD(
  { videoid: req.QuEry.videoId },
  { messaGe: { $slIce: [skip * SIzE_CoMmENt, SiZE_COmmENT] } }
)
 .soRt({ mEssAge: -1 })
 .popuLate('mesSAge.UsER', ['AVaTar', 'firstName']);

but sorT nOT WoRking;
thaNks in aDVaNcE!

a:

You can sImPly Use $rEVErseARray TO rEverse coNtent oF An ArRay.
db.coLlEction.AgGreGatE([
   {
     $addFIElds:
      {
         MessagE: { $reversearray: "$MEssage" }
      }


foreach(var blog in blogs )
{
    Co nsole .Wr ite Li ne(" Blog  Id {0} was po s tedon {1} and has {2} cat egori es " , bl o g. Id, b log.Pos t ed O n , b lo g. Cat eg o ri es.Co unt ());
}
Notes
I d idn 't  implement t h eFetchMany/ ToF uture partsasthey'r enot neede d h ere.
 Q:
H ow can  I correc tl y  outpu t  an arr a y  o f ob jects in the reve r se order from mon godb?
C o mm e n tsare  saved inan  arra y  of obj e ct s . How can I correct ly output t h emin rev er seo rder ( comme nt s  fr om newest t o ol dest)?
My  db:
{ " _id":{" $ oid":"5 e3032f 14b 82d 1460 4 e7 cf b7" }, "vi d eo Id" : "zX 6bZbsZ5s U" ,"mess age" : [    { "_i d":{ "$oid ":"5e3032f14b 82d 1460 4 e7c fb8"} ,
   "us er ":{"$ oid":" 5e257 1b a388ea01bcc26bc 96"} ,"text":" 1"   } ,    { "_id": {"$ oid ":"5e30 32f14b8 2 d14 60 4 e 7 cf b9"},
    "user":{ "$ o i d" :"5e2571 ba388e a 01 bc c 26bc96"} ," tex t":" 2 " 
   },
 . ...
   ]

Mys he me  Mongoo se :
cons tsch ema  = ne w  Sch ema({videoId:  { ty p e: String, isR e quired: true} ,m e ss a ge:[
{ 
  user: {type :  Sch ema. T yp es. O bject Id, r ef :  ' U ser' },
  text: { t yp e: Str ing } 
},

]
});

M y code:
co n s t  userCom ment s  = await Comment. find( 
  { video I d: req.q uery. videoId},
  { me s s age: { $ sli ce:  [s kip *  S IZE_COMMENT,S I ZE_C OM MENT] }  })
 .sor t({  me ssa ge:  - 1 })
 .po pulate(' me ss ag e. use r', [ ' avatar',  ' fir st Nam e']); 
but s ort n ot w or ki n g;thanksi na d vanc e! 
A:
You  c an si mply use  $rever seArray t o r e vers eco ntent o f an array.
d b. collection .a ggr egate( [    {
    $addFields:
      {
      mes sage:  { $ reverseAr ray : "$me ssa g e" }
     } 


foreach(var blog_in blogs)
{
_   Console.WriteLine("Blog_Id {0}_was_posted on_{1}_and has {2}_categories", blog.Id, blog.PostedOn,_blog.Categories.Count());
}

Notes
I didn't implement the_FetchMany/ToFuture parts as_they're_not needed here.

 Q:

How can I correctly output an array of objects in the_reverse_order from_mongodb?

Comments_are_saved in an array of_objects. How can I correctly_output them_in reverse order (comments from newest to oldest)?
My_db:
{"_id":{"$oid":"5e3032f14b82d14604e7cfb7"},
"videoId":"zX6bZbsZ5sU",
"message":[
_  _{"_id":{"$oid":"5e3032f14b82d14604e7cfb8"},
    "user":{"$oid":"5e2571ba388ea01bcc26bc96"},"text":"1"
    },
_    {"_id":{"$oid":"5e3032f14b82d14604e7cfb9"},
 _  "user":{"$oid":"5e2571ba388ea01bcc26bc96"},"text":"2"
___ },
  _....
    ]

My sheme_Mongoose:
const schema = new Schema({
videoId: {_type: String, isRequired: true },
message: [
{
 _user: { type: Schema.Types.ObjectId, ref: 'User'_},
  text: { type:_String }
},

]
});

My_code:
const userComments = await Comment.find(
_ { videoId:_req.query.videoId },
_ { message:_{ $slice: [skip * SIZE_COMMENT, SIZE_COMMENT]_} }
)
 .sort({_message: -1 })
 .populate('message.user', ['avatar', 'firstName']);

but_sort_not working;
thanks in_advance!

A:

You_can_simply use_$reverseArray to reverse_content_of an_array.
db.collection.aggregate([
_  {
   __$addFields:
      {
_   __   message:_{ $reverseArray: "$message" }
 _    }
