Projection predicate select all in array

how can i select all in array by predicate .
like Reading Documents: Array Fields

instead of {cast [“Jeff”,“allan”]}
i want to {cast [all input]}

It’s not completely clear. You want to convert an array to one long string?

By the way, is your questions supposed to be linked to any course? E.g. M121 Aggregation Framework?

thanks for the reponse, just like this
cursor = await book.find(
{ author: },
{ projection: { title: 1} }

i want to project just a titile with predicat all author.

author is a array object

i am new with nosql, i came from sql.
i think -->
select xx is equal projection in mongodb
where xx is equal predicat in mogodb

so select title from book; --> normaly book.find(
{ projection: { title: 1} }

why do i need put predicat ? is predicate obligate ?

I’m still struggling to understand your explanation but perhaps one the array operators in this link might help?

Still waiting for a response to this :arrow_up:?

Hi @Stev_80585

In a general sense yes

I see your example is looking in the book collection. If all you are after is all the titles to the books then, no you do not need a query (predicate).

As @007_jb has pointed out, when working with arrays and trying to query against them see these docs.

nope …it is exercise projection movies

I’ve linked your thread to the course. Remember to do so next time.

I believe that @natac13 has answered your question?

not realy…i dont’ know if i can poste the answer in this forum.
btw i still got error

cursor = await movies.find(

    { countries: { $all: [ "Russia", "Japan", "Mexico" ,"Kosovo"] } },

    { projection: { title: 1} }

like natac13 said that the predicat is not obligation…then i can omitted…i got the same error anyway.

my config:

You do need the predicate. But the one you show is wrong. Why do you have russia, japan and mexico? The unit test is for kosovo only. Do you hard code the values in your code?

thanks…why i need predicate ?

just like select title from movies.

there are no where statement

i don’t know what i should put in predicate.
tried like this
cursor = await movies.find(


      { projection: { title: 1} }


still got the same error

If you select title from movies you will not get the movies from kosovo. You would probably do select title from movies where countries has kosovo. You achieve the same with $all.

In addition, I do not think you are doing a lab from M121. You should link your thread to M220JS as your code looks like JavaScript. I also recommend that you should take M001 first.


thanks …what is equivalent “in” in mongo

select title
from movies
where countries in (“Russia”, “Japan”, “Mexico” ,“Kosovo”)

got it like this
cursor = await movies.find(

    { countries: { $in: [countries ] }} ,

      { projection: { title: 1} }


the first countries is a field name
the second countries is a input arrays…still the same error

it is strange …when i use

cursor = await movies.find(

    {   countries:  "Kosovo"  },

      { projection: { title: 1} }


i got 1 correct --> the kosovo one

when i use this
cursor = await movies.find(

    { countries: { $in: ["Russia", "Japan", "Mexico"] } } ,

      { projection: { title: 1} }


i got the other correct 3 countries

but when i combine it…i got 0 corect
cursor = await movies.find(

    {  $or: [ { countries:  "Kosovo"  }, { countries: { $in: ["Russia", "Japan", "Mexico"] } } ] } ,

      { projection: { title: 1} }


i resolve it…thanks…all

1 Like