Hi David,
read your post and most of the replies here. It seems you’re having issues with the right syntax for your aggregation pipelines.
Did the M121 couple weeks ago, and as I started, me, too, I certainly had issues with my syntax then.
So I decided, I’m gonna need a syntax checker to manage all that opening and closing braces and brackets.
From the get go, I had not so much luck working directly in MongoDB Compass or in the Mongo Shell.
However, I “discovered” that the Mongo Shell did accept writing my documents in JavaScript like db.users.find({ name: 'John Doe' })
, it was not necessary to write my documents in JSON like db.users.find({ "name": "John Doe" })
.
Therefore, I could just grab my Vim or Emacs and write my dcuments – and later aggregation pipelines – inside a JavaScript file enjoying all the syntax highlighting and checking that were to be enjoyed.
First writing my documents using Vim / Emacs / VSCode JavaScript editor and then copying the ready-made syntax in my Mongo Shell was kind of the breakthrough.
By the way, I soon discovered the MongoDB Extension for VSCode with its Mongo Playgrounds. Brought it all one notch higher …
Maybe such would help you, too? Regards, M.
Update #1 at Thu Feb 25 16:39:01 CET 2021
Please also consider the reply from @steevej-1495 below, which is true and might very much prevent beginners from being mislead by my simple code eamples demonstrating some degree of acceptance of JavaScript code within the Mongo Shell.
@steevej-1495 , thank you very much for your commitment and for commenting my short remarks.