I am trying to make a query in MongoDB
, and it is not clear to me how to do it.
Through the following line, I get the displayed:
I would like to know if there is any way to get only the field in question, ie "qfmSLTmr3tyZwykaA" and not everything that precedes it.
Or treat it somehow throughjavascript
When you perform a search in a collection and you want to exclude one or several fields, you can use 0 to indicate not to show the field:
to include it we use 1
In the case of what you are doing, you are obtaining all the elements of the collection but you only show the "building" field, while you exclude the "_id" field:
with this result:
If you want to obtain only the value (or the values of a certain field) it is obtained in this way:
with this you will get only the value of the field
edificio
If possible. This query method is called Projection . The method
find
accepts two objects as parameters:Your query will look like this when using Projection :
The integer is binary, that is, it accepts only
0
and1
. By default, the_id
will also be selected, if you don't want this behavior you can override it by setting0
the_id
: