2011-07-20 64 views
2

我在蒙戈集合,其中與此類似記載:如何在Mongo中獲得獨特的屬性?

{ "id": NumberLong(141242), "name": "John Doe", "language": "en" } 
{ "id": NumberLong(3556332), "name": "Mark Zuckerberg", "language": "jp" } 
{ "id": NumberLong(124), "name": "Abigail Fidler", "language": "cn" } 
{ "id": NumberLong(325262351), "name": "Joe Parker", "language": "jp" } 
{ "id": NumberLong(98798), "name": "John Bush", "language": "en" } 

,我想從該集合中選擇所有獨特的語言。

{ "language": "en" } 
{ "language": "jp" } 
{ "language": "cn" } 

有什麼辦法如何在Mongo中做到這一點?

回答

1

MongoDB對此有一個distinct命令。從mongo

實施例:

> db.mydb.distinct("language"); 
[ "en", "jp", "cn" ]