Home > Software engineering >  In MongoDB Projection Operator, what is the meaning of the parameter "1" in "<arra
In MongoDB Projection Operator, what is the meaning of the parameter "1" in "<arra

Time:09-23

I'm starting to learn MongoDB, currently, I'm on the Projection Operator lesson. I want to ask about $ (projection). According to MongoDB document, the syntax is like

db.collection.find( { <array>: <condition> ... },
                    { "<array>.$": 1 } )

I want to ask about the parameter "1" in { "<array>.$": 1 }. What is the meaning of that? At first, I think it means "first element" but when I change it to "2" it doesn't show the second element, it was still the same. I can't find any information about this parameter on the internet

CodePudding user response:

If you pass 1 as a value of some field in the projection, you are specifying that you want that field to be included in the result.

That is the optimization, since not all the fields will be sent back (default), but only the fields that you specified.

  • Related