Pipeline stage error

i am getting 23 documents back. it is loading into the variable pipeline. but when i run db.movies.aggergate(pipeline).itcount() or validateLab1(pipeline) i get the following error.

MongoDB Enterprise Cluster0-shard-0:PRIMARY> load("/Users/mkastle/MongoDB\ University/M121/chapter1/validateLab1.js")
command failed: {
“operationTime” : Timestamp(1537822243, 1),
“ok” : 0,
“errmsg” : “A pipeline stage specification object must contain exactly one field.”,
“code” : 40323,
“codeName” : “Location40323”,
“$clusterTime” : {
“clusterTime” : Timestamp(1537822243, 1),
“signature” : {
“hash” : BinData(0,“50x8foyUTr+9tUAYQIyLpCAHHRc=”),
“keyId” : NumberLong(“6559514413705986049”)
}
}
} : aggregate failed
true

Hi,

Were you able to find the issue? Please send me your pipeline as a private message.

José Carlos

it says im not allowed to send you a personal message.

Hi,

I would suggest to test your pipeline adding a new stage at a time. Does db.movies.aggergate(pipeline) return the expected results?

José Carlos

no same error

db.movies.count

and

db.movies.aggregate($match) with $count: “title”

returns 23

sorry. yes db.movies.aggregate(pipeline) does

db.movies.aggregate(pipeline).itcount() returns same error

Hi @michael_00217,

Please make sure you just assign the pipeline variable the array of stages:

var pipeline = [{stage 1}, {stage 2} ... ];

Hope this helps.

José Carlos

pipeline = db.movies.aggregate([{
“$match”: {"$and": [{"": { “”: }},
{"": { “”: ["", “”]}},
{"": {"": ["", “”]}},
{"": { “”: ["",""]}}]
}
}])

pipeline = db.movies.aggregate([
{ “$match”: {"": { “”: }}},
{ “$match”: {"": { “”: ["", “”]}}},
{ “$match”: {"": {"": ["", “”]}}},
{ “$match”: {"": { “”: ["",""]}}}
}])

i have tried both of these

Hi,

Try this:

var pipeline = [
{ "$match": {"": { “”: }}},
{ "$match": {"": { “”: ["", “”]}}},
{ "$match": {"": {"": ["", “”]}}},
{ "$match": {"": { “”: ["",""]}}}
}];

db.movies.aggregate(pipeline)

JC

thank you. and i understand why i was wrong.

You are welcome! If you take a look at the validateLab1.js file you’ll see it expects a variable called pipeline to be passed to the aggregate method.

José Carlos