Chapter 1 Lab - Computing Fields ($match or $project)

Should the $size and $split operations be done on $match or $project?

I have referenced everything provided (video, documentation, even other sites), but to no avail. I’m just making educated guesses at this point with the proprietary syntax. Are there any other hints to point me in the right direction. Filtering first with $match seems the most logical. Otherwise, $match would just be returning every title in the collection. In Java I’d just do something simple like title.split(" ").length==1 to get one word titles, but I can’t get any variation of this syntax to work.

I’d post what I’ve tried so far, but I don’t want to infringe on the request to not post answers (not that my answer is working anyway). Thanks for any help.


In general, you would only use $split in a $project expression – since this only changes the shape of a document by splitting up a string and would not change or reduce the number of documents, it would have no use in a $match. $size might be used in either, but usually it would be in a $match to ensure that subsequent stages of the pipeline have documents that have a certain number of elements.

You mention that you have already reviewed the docs, but you might want to re-read those two pages and just think some more about the uses of both operators. HTH.

Thanks DHz. This was very helpful. I approached it somewhat differently (not knowing the proper strategy) but was able to derive the correct answer. This got me to the point where I could see the Detailed Answer and learn the proper strategy.