"errmsg" : "A pipeline stage specification object must contain exactly one field."

I’m solving the homework in Chapter 1.
I’m able to create the var pipeline, which has 23 documents, but when I run further commands like:

I get the following error:
assert: command failed: {
“operationTime” : Timestamp(1535089663, 1),
“ok” : 0,
“errmsg” : “A pipeline stage specification object must contain exactly one field.”,
“code” : 40323,
“codeName” : “Location40323”,
“$clusterTime” : {
“clusterTime” : Timestamp(1535089663, 1),
“signature” : {
“hash” : BinData(0,“7uz1RnBiJH/GFZp9WTUjnaroYbQ=”),
“keyId” : NumberLong(“6559514413705986049”)
} : aggregate failed

How do I solve for it?


It’s difficult to guess without seeing your pipeline, it might be because you have an invalid stage or because you didn’t specify every stage as a different JSON document in the array, or something like that. Please check if you are able to send me your pipeline through a private message.

José Carlos

how do I send a private message?


It might be that feature is not enabled for everyone… Try clicking on my username and let me know if there’s a messages link there. I would suggest to test your pipeline one stage at a time, so you can know where it fails exactly.

José Carlos

Your assignment has to follow this pattern of the validateLab1 to work.
var pipeline = [ { “$match” : { your logic } } ]
I was trying to do db.aggregations(‘movies’).aggregate({ “$match” : { your logic } }) and was getting the same error.


Yes. That fixed it. Thanks!