Pipeline error, code 40323, its gotta be a missing bracket, right?

I am working on an aggregation pipeline to compile data to push to the frontend for a chart to render, which involves 3 collections (one of which is just a reference to the other 2). Individually on the collections, I am able to get the expected response on the aggregation, but when trying to incorporate the aggregations together with $lookup, I keep getting the error:

query failed: (Location40323) A pipeline stage specification object must contain exactly one field.

From what I’m reading in other user’s threads on this error, its either a missing bracket, or a property being set outside the appropriate bracket. However, for the life of me, I cannot find any missing brackets. I’m still learning mongoDB, and (coding in general…) so I’m certain its some silly mistake/oversight, but I’ve been running through the code over and over and coming up short. If anyone can help point out the errors I’m making, I’d greatly appreciate it.

I’ve made a playground with the example:

Yup, was the brackets, I was tripping myself up adding the {} in the $lookup pipelines. Each time I went to the add the brackets, I was accidentally wrapping each condition within a greater object of the pipeline array, for example :

pipeline: [
{$match:… },
{$lookup: …}
Just needed to take a break and come back to it, was staring too long and got lost in the braces…


You know, that sounds a little like a normalized relational schema which isn’t usually the best way to go for MongoDB…. :slight_smile:

P.S. glad you were able to get the syntax resolved.

1 Like

Well the initial collection has a lot of other properties and at scale the documents would exceed the 16mb limit if I nested the other 2 collections, so I tie them together with ref’s. As far as I’m aware, that is the preferred mongo way of approaching it, but I am always open to suggestions.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.