The destinct command for MongoDB is to get a list of different values in a particular field. This command applies to normal fields, array fields, and arrays of embedded documents.
MongoDB's distinct statement:
Copy Code code as follows:
Db.users.distinct (' last_name ')
Equivalent to an SQL statement:
Copy Code code as follows:
Select DISTINCT last_name from Users
Represents the return of a different recordset based on the specified field.
A simple example:
> Db.addresses.insert ({"Zip-code": 10010})
> Db.addresses.insert ({"Zip-code": 10010})
> Db.addresses.insert ({"Zip-code": 99701})
>//Shell helper:
> Db.addresses.distinct ("Zip-code");
[10010, 99701]
>//Running as a command manually:
> Db.runcommand ({distinct: ' Addresses ', key: ' Zip-code '})
{"Values" : [10010, 99701], "OK"
//
> Db.comments.save ({"user": {"Points":}})
> Db.comments.save ({"User ': {' points ': [to}}]
> Db.comments.save ({"user": {"Points":}})
> db.comments.distinct ("user.points ");
[25, 31]
The above mentioned is the entire content of this article, I hope you can enjoy.