Mongoose: jak ustawić pole schematu na ID?

Biorąc pod uwagę następujący schemat:

<code>var UserSchema = new Schema({
   , email   :  { type: String }
   , passwordHash   :  { type: String }
   , roles  :  { type: [String] }
});
</code>

chciałbymemail być kluczem. Jak mogę to zdefiniować?

Mógłbym zrobić:

<code>var UserSchema = new Schema({
       , _id:  { type: String }
       , passwordHash   :  { type: String }
       , roles  :  { type: [String] }
    });
</code>

więc MongoDB rozpoznałoby to jako pole id i dostosowało mój kod tak, aby się odwoływał_id zamiastemail ale to nie jest dla mnie czyste.

Ktoś?

questionAnswers(1)

yourAnswerToTheQuestion