Queries on Array Fields,

Help me use Queries on Array Fields,

image
dont work,
work only
{genres :“Western”}

How use Queries on Array in Compas 4.0.5?

1 Like

Should be {genre: " The genre you are looking for} so for this {genre: “Western”} It also doesn’t like the S when you entered in genres.

image

you have to use quotes from 4.0 . Below is form lecture notes.

  • At minute 3:30 Shannon mentions that you do not need to use quotes while building your queries in MongoDB Compass. This is no longer correct! You need to provide quotes when using the dot notation to express queries.

dont work

please use the double quotes for the key {“genres.1”:“Western”}

1 Like

in the composs we dont need to use quotes thats for shell

Please use quotes surrounding every field name and field value (if it is string not number).
Dont omit quotes as it will give u error

And how does one concatenate array search strings?

In the video it says to concatenate string sepperated with commas:
Like:
db.movieDetails.find({“genres”: “Action, Adventure”}, {title: 1, _id:0}).count()
0
But I get 0 results (and there are genres that are “Action” and “Adventure”.

Only querying “Action” does give 278 results:
db.movieDetails.find({“genres”: “Action”}, {title: 1, _id:0}).count()
278

But how do I correctly query for “Action” AND “Adventure”?

use the query:

db.movieDetails.find({“genres”: [“Action”,“Adventure”] })

i may have a theory.
If you are following the video, it was referring to another database located in M001RS.
(in this database, the collections spits out result because genres is the key being used not “genre”, “genre is the key for movieDetails db” )

@mr_jimmybob.
your query is the same as well.
(it’s not available in movieDetails db because none
of its entries has ONLY Action, Adventure).


1 Like