Retrieves all unique values for a specific property.
Method definition
distinct(key: string, query: object): Promise<MongoResult>Request parameters
Field name | Type | Required | Description |
| String | Yes | The name of the property to retrieve. |
| Object | Yes | The query conditions for the database operation. |
Request example
Returns all unique
namevalues for users whoseageis greater than 18.
mpserverless.db.collection('users').distinct(
'name',
{ age: { $gt: 18 } }
)
.then((res) => {})
.catch(console.error);Result example
Successful response:
{
"affectedDocs": 2,
"result": ["Zhang San", "Li Si"],
"success": true
}该文章对您有帮助吗?