Mongoose - distinct方法

示例数据:

{
    "_id" : ObjectId("5c9d8cc3161d6c257c021340"),
    "email" : "123@123com"
}
{
    "_id" : ObjectId("5ca2bc4a54bc0f2fa07b1541")
    "email" : "234@234.com"
}
{
    "_id" : ObjectId("5ca2cb7a9f464a1710a3f28c"),
    "email" : "345@345.com"
}

执行:

db.getCollection('users').distinct('email')

结果:


[
    "123@123.com",
    "234@234.com",
    "345@345.com"
]

版权声明:本文为seaalan原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。