Mongoose - Get list of _ids instead of array of objects with _id

后端 未结 1 2055
盖世英雄少女心
盖世英雄少女心 2021-02-12 19:32

I would like to run following query:

Group.find({program: {$in: [...]}}).lean().select(\'_id\')

And then NOT get following bac

1条回答
  •  说谎
    说谎 (楼主)
    2021-02-12 20:04

    Group.find({program: {$in: [...]}})
      .distinct('_id')
    

    db.collection.distinct(field, query)

    Finds the distinct values for a specified field across a single collection and returns the results in an array.

    Read more.

    0 讨论(0)
提交回复
热议问题