Error on validateLab1(pipeline)- getting "errmsg" : "A pipeline stage specification object must contain exactly one field.",

Hello,

when I query pipeline count it is giving 23 records. and I am able to load and when I execute validateLab1(pipeline) I get following message

assert: command failed: {
“operationTime” : Timestamp(1540226263, 7),
“ok” : 0,
“errmsg” : “A pipeline stage specification object must contain exactly one field.”,
“code” : 40323,
“codeName” : “Location40323”,
“$clusterTime” : {
“clusterTime” : Timestamp(1540226263, 7),
“signature” : {
“hash” : BinData(0,“2oBVlT0uiHZ6sCbPwEvcjdlsGOE=”),
“keyId” : NumberLong(“6559514413705986049”)
}
}
} : aggregate failed
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:16:14
assert.commandWorked@src/mongo/shell/assert.js:403:5
DB.prototype._runAggregate@src/mongo/shell/db.js:260:9
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1212:12
validateLab1@validateLab1.js:7:20
@(shell):1:1

command failed: {
“operationTime” : Timestamp(1540226263, 7),
“ok” : 0,
“errmsg” : “A pipeline stage specification object must contain exactly one field.”,
“code” : 40323,
“codeName” : “Location40323”,
“$clusterTime” : {
“clusterTime” : Timestamp(1540226263, 7),
“signature” : {
“hash” : BinData(0,“2oBVlT0uiHZ6sCbPwEvcjdlsGOE=”),
“keyId” : NumberLong(“6559514413705986049”)
}
}
} : aggregate failed…

I have created following pipeline query: removing all inside just giving top section how $match is done

db.movies.aggregate([{
$match: {

    $and: [{"imdb.rating": {}},{
            "languages": {
                $all:[]}},  {
            "rated": {
                $in:[]}},,
        {
            "genres": {
                $nin: []}}, ]
}

}, ])

I got proper. count.

pls guide me whether I need to use any $projection to get only one field in output?

also I have added
var pipeline=db.movies.aggregate([{
$match: {

whole query.

not sure if I am missing something in variable assignment

HI,

I am able to figure out the issue. I was assigning actual data to pipeline instead of $match condition

thanks for your help

Hi,

Glad you managed to solve it. The pipeline variable should be the array of stages, not the result of the aggregation query, i.e., var pipeline = [{stage1}, {stage2}]

José Carlos

1 Like

Hi, @jcarlosgarcia, when you talk about “The pipeline variable should be the array of stages”, do you want to say which each filter should be a stage or should have a stage with the filters and other with the count(*). My $match expression returns 23 rows but I get the subject’s error when I run it.

It’s nice to know a compatriot in this forum :slight_smile:

Thank in advanced

@luisjmlky this thread is over a year old.

For this lab, the pipeline should be a $match stage that is an array of filters/expressions/conditions. And I don’t understand what you mean by “subject error”… can you elaborate?

Hi @007_jb, sorry, the “subject error” is the title of this thread “A pipeline a stage specification…”.

Thx

In order for the validator to work, the pipeline variable needs to be in this form:

var pipeline = [
  {
    $match: {
      <filter1>,
      <filter2>,
      ... etc ...
    }
  }
]

Ok, now I know where is the problem, I wrote:

image

A question more please, is right show your possible solution (the code) when you are asking in a thread?

Thx

The lab and exam questions are recycled so it won’t be fair to current/prospective students if they come across an answer whilst browsing through a thread.

Ok, I will not show my code.

Thx @007_jb

1 Like

Hi @luisjmlky,

Please check your discourse inbox.

Let me know, if you have any questions.

Thanks,
Sonali