Skip to main content

Select

The Select method is used to specify which fields to include in the results.

Usage

witchers := WitcherModel.Find().Select("name", "age").ExecTT()

In the example above, we are selecting only the name and age fields from the Witcher documents.

Usage with a string input

witchers := WitcherModel.Find().Select("name age").ExecTT()

Usage with a map input

witchers := WitcherModel.Find().Select(primitive.M{
    "name": 1,
    "age":  1,
}).ExecTT()

Usage with a slice input

witchers := WitcherModel.Find().Select([]string{"name", "age"}).ExecTT()