I'm in the process of setting up a blog where each post consists of multiple paragraphs. My goal is to be able to count the number of paragraphs in a specific post. The structure of my "Blog" collection, which contains documents (posts), looks like this:
{ id : String
title : String
paragraphs : [ { position: Int, body: String } ] }
I'm looking for a function that will return an Integer value. Maybe something along the lines of:
var NumberParagraphs = Blog.find( {id: id} ).paragraphs.length
(of course, this code doesn't actually work!). Can you guide me on how to approach this issue? I've been researching online and getting confused between using .count()
, $size
, or .aggregate
.