Mongoose - distinct方法

示例数据:

{
    "_id" : ObjectId("5c9d8cc3161d6c257c021340"),
    "email" : "123@123com"
}
{
    "_id" : ObjectId("5ca2bc4a54bc0f2fa07b1541")
    "email" : "[email protected]"
}
{
    "_id" : ObjectId("5ca2cb7a9f464a1710a3f28c"),
    "email" : "[email protected]"
}

执行:

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

结果:


[
    "[email protected]",
    "[email protected]",
    "[email protected]"
]

猜你喜欢

转载自blog.csdn.net/seaalan/article/details/89251285