I would like to know if there is a way to return only the _id, user_id and total without the items subdocument.
{
"_id" : 122,
"user_id" : 123456,
"total" : 100,
"items" : [
{
"item_name" : "my_item_one",
"price" : 20
},
{
"item_name" : "my_item_two",
"price" : 50
},
{
"item_name" : "my_item_three",
"price" : 30
}
]
}
The second parameter of find lets you select fields. So you can use this (note that the _id field is always selected anyway):
You can also exclude certain fields, so this would be equivalent:
You can exclude _id field by doing: