$or operator issue

Hi everyone,
During “Logical operator” lecture I noticed that my result is different than tutor has.
for request:
db.getCollection('movieDetails').find( {$or: [ {"tomao.meter":{$gt:95}}, {"metacritic":{$gt:88}} ] }, {"title" : 1, "tomato.meter" : 1, "metacritic" : 1, "_id" :0})
I have:
{
“title” : “L.A. Confidential”,
“tomato” : {
“meter” : 99.0
},
“metacritic” : 90.0
}

/* 2 */
{
“title” : “La Dolce Vita”,
“tomato” : {
“meter” : 96.0
},
“metacritic” : 93.0
}

/* 3 */
{
“title” : “No Country for Old Men”,
“tomato” : {
“meter” : 93.0
},
“metacritic” : 91.0
}

/* 4 */
{
“title” : “There Will Be Blood”,
“tomato” : {
“meter” : 91.0
},
“metacritic” : 92.0
}

/* 5 */
{
“title” : “E.T. the Extra-Terrestrial”,
“tomato” : {
“meter” : 98.0
},
“metacritic” : 94.0
}

/* 6 */
{
“title” : “Au Hasard Balthazar”,
“tomato” : {
“meter” : 100.0
},
“metacritic” : 100.0
}

/* 7 */
{
“title” : “Toy Story 3”,
“tomato” : {
“meter” : 99.0
},
“metacritic” : 92.0
}

/* 8 */
{
“title” : “The Wizard of Oz”,
“tomato” : {
“meter” : 99.0
},
“metacritic” : 100.0
}

/* 9 */
{
“title” : “Star Wars: Episode IV - A New Hope”,
“tomato” : {
“meter” : 94.0
},
“metacritic” : 92.0
}

/* 10 */
{
“title” : “Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb”,
“tomato” : {
“meter” : 99.0
},
“metacritic” : 96.0
}

/* 11 */
{
“title” : “The Adventures of Robin Hood”,
“tomato” : {
“meter” : 100.0
},
“metacritic” : 97.0
}

/* 12 */
{
“title” : “The Truman Show”,
“tomato” : {
“meter” : 94.0
},
“metacritic” : 90.0
}

/* 13 */
{
“title” : “Raiders of the Lost Ark”,
“tomato” : {
“meter” : 96.0
},
“metacritic” : 90.0
}

/* 14 */
{
“title” : “Lost in Translation”,
“tomato” : {
“meter” : 95.0
},
“metacritic” : 89.0
}

/* 15 */
{
“title” : “The Night of the Hunter”,
“tomato” : {
“meter” : 98.0
},
“metacritic” : 99.0
}

/* 16 */
{
“title” : “Toy Story”,
“tomato” : {
“meter” : 100.0
},
“metacritic” : 92.0
}

/* 17 */
{
“title” : “Toy Story 3”,
“tomato” : {
“meter” : 99.0
},
“metacritic” : 92.0
}

You can see that “OR” doesn’t work well.
It doesn’t show results when “tomao.meter” > 95 and “metacritic” < 88.
Does anyone faced with this?

P.S. I use Robo3T instead of Mongo shell

Hey @Siarhei_32861
Looks like your syntax is off slightly. tomao.meter should be tomato.meter
Then with a query as follows:

db.movieDetails.find( {$or: [ {"tomato.meter":{$gt:95}}, {"metacritic":{$gt:88}} ] }, {"title" : 1, "tomato.meter" : 1, "metacritic" : 1, "_id" :0}).pretty()

Which returns 39 documents! :slight_smile: This can be shown by adding .count() at the end as follows:

db.movieDetails.find( {$or: [ {"tomato.meter":{$gt:95}}, {"metacritic":{$gt:88}} ] }, {"title" : 1, "tomato.meter" : 1, "metacritic" : 1, "_id" :0}).count()

Also have you given MongoDB Compass a try?

1 Like

Shame on me :man_facepalming: Thanks!