Why zero records return . Lab1

Hello,

Finally got it working I think

var pipeline = [{      $match: {          "idbm.rating": {              $gt: 7          },          "$or": [              {"genres": {$ne: "Horror"}},              {"genres": {$ne: "Crime"}}          ],           "$or": [{              "rated": "PG"          }, {              "rated": "G"          }],                       "languages": {              $in: ["English", "Japanese"]          }      }  }]
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.aggregate(pipeline).itcount()

but when I run it, I see that no records are returned.
Anyone who can give me a hint why. As far as I can see I did all the cases right

Try each case, one by one until you find which one is wrong.

Also make sure you are using the appropriate database.

I did but no luck
Even this one gives zero:

 var pipeline = [{$match: {"idbm.rating": {$gte: 7}}}]
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.aggregate(pipeline).itcount()
0

and the last line comes right from the lesson
and the match seems also be well if I read the description :

imdb.rating is at least 7

now I complete surpised

 var pipeline = [
...         {
...                 "$match" : {
...                         "imdb.rating" : {
...                                 "$gt" : 7
...                         },
... "$or" : [
...                                 {
...                                         "genres" : {$ne: "Horror"},
...
...                                 },
...                                 {
...                                         "genres" : {$ne: "Crime"}
...                                 }
...                         ],
...                         "$or" : [
...                                 {
...                                         "rated" : "PG"
...                                 },
...                                 {
...                                         "rated" : "G"
...                                 }
...                         ],
...                         "languages" : {
...                                 "$in" : [
...                                         "English",
...                                         "Japanese"
...                                 ]
...                         }
...                 }
...         }
... ]
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.aggregate(pipeline).itcount()
819
MongoDB Enterprise Cluster0-shard-0:PRIMARY> pipeline
[
        {
                "$match" : {
                        "imdb.rating" : {
                                "$gt" : 7
                        },
                        "$or" : [
                                {
                                        "rated" : "PG"
                                },
                                {
                                        "rated" : "G"
                                }
                        ],
                        "languages" : {
                                "$in" : [
                                        "English",
                                        "Japanese"
                                ]
                        }
                }
        }
]

it looks my changes are not stored at all . Why ???

you wrote idbm.rating rather than imdb.rating

yep.

I thought this would solve it but again the same error as before :

 pipeline
[
        {
                "imdb.rating" : {
                        "gte" : 7
                },
                "$and" : [
                        {
                                "$or" : [
                                        {
                                                "genre" : {
                                                        "$ne" : "Crime"
                                                }
                                        },
                                        {
                                                "genre" : {
                                                        "$ne" : "Horror"
                                                }
                                        }
                                ]
                        },
                        {
                                "$or" : [
                                        {
                                                "rated" : "PG"
                                        },
                                        {
                                                "rated" : "G"
                                        }
                                ]
                        }
                ],
                "languages" : {
                        "$nin" : [
                                "English",
                                "Chinese"
                        ]
                }
        }
]
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.aggregate(pipeline).itcount()
uncaught exception: Error: command failed: {
        "operationTime" : Timestamp(1600712513, 1),
        "ok" : 0,
        "errmsg" : "A pipeline stage specification object must contain exactly one field.",
        "code" : 40323,
        "codeName" : "Location40323",
        "$clusterTime" : {
                "clusterTime" : Timestamp(1600712513, 1),
                "signature" : {
                        "hash" : BinData(0,"Vyp6Y/hOFkyKr5viJGl1luYEIQ4="),
                        "keyId" : NumberLong("6829321948548300802")
                }
        }
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:618:17
assert.commandWorked@src/mongo/shell/assert.js:708:16
DB.prototype._runAggregate@src/mongo/shell/db.js:266:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1046:12
@(shell):1:1

This is no fun anymore

gte is an operator so it must be written as $gte.

and it is genres rather than genre

Thanks, changed but still the same error :

[
        {
                "imdb.rating" : {
                        "$gte" : 7
                },
                "$and" : [
                        {
                                "$or" : [
                                        {
                                                "genres" : {
                                                        "$ne" : "Crime"
                                                }
                                        },
                                        {
                                                "genres" : {
                                                        "$ne" : "Horror"
                                                }
                                        }
                                ]
                        },
                        {
                                "$or" : [
                                        {
                                                "rated" : "PG"
                                        },
                                        {
                                                "rated" : "G"
                                        }
                                ]
                        }
                ],
                "languages" : {
                        "$nin" : [
                                "English",
                                "Chinese"
                        ]
                }
        }
]

I do not think the requirement is to not have English and Chinese.

you are right

languages contains "English" and "Japanese"
`` `
it needs to be $in 

but that does not solve this annoying error message : 

var pipeline = [{ “imdb.rating”:{ “$gte”:7 }, “$and”:[ { “$or”:[ { “genres”:{ “$ne”:“Crime” } }, { “genres”:{ “$ne”:“Horror” } } ] }, { “$or”:[ { “rated”:“PG” }, { “rated”:“G” } ] } ], “languages”: { $in: [“English”, “Chinese”] } } ]
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.aggregate(pipeline).itcount()
uncaught exception: Error: command failed: {
“operationTime” : Timestamp(1600715783, 1),
“ok” : 0,
“errmsg” : “A pipeline stage specification object must contain exactly one field.”,
“code” : 40323,
“codeName” : “Location40323”,
“$clusterTime” : {
“clusterTime” : Timestamp(1600715783, 1),
“signature” : {
“hash” : BinData(0,“DGTjMLBeF4+UdGcahAvYJdLRMDU=”),
“keyId” : NumberLong(“6829321948548300802”)
}
}
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:618:17
assert.commandWorked@src/mongo/shell/assert.js:708:16
DB.prototype._runAggregate@src/mongo/shell/db.js:266:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1046:12
@(shell):1:1

and now, you are missing the $match

Did all the changes but still a wrong answer

var pipeline = [         {                 "$match" : {                         "imdb.rating" : {                                 "$gte" : 7                         },                         "$and" : [                                 {                                         "genres" : { "$not" : { "$in" : [ "Crime" , "Horror" ] } }                                 },                                 {                                         "$or" : [                                                 {                                                         "rated" : "PG"                                                 },                                                 {                                                         "rated" : "G"                                                 }                                         ]                                 }                         ],                         "languages" : {                                 "$in" : [                                         "English",                                         "Japanese"                                 ]                         }                 }         } ]

Hi @Roelof_Wobben,

Closing out this thread as it is duplicate discussion.

Feel free to reply with your doubts on the discourse inbox thread that I have initiated with you.

Thanks,
Sonali