2013-02-26 33 views
26

tôi đang cố gắng để xác nhận và lưu hồ sơ hộ chiếu với cấu trúc này:lĩnh vực cầy mangut với tên loại

http://passportjs.org/guide/profile/

Đây là chương trình tôi đã đưa ra:

// Define the schema. 
schema = new mongoose.Schema({ 
    // The name of this user, suitable for display. 
    displayName: String, 
    // Each e-mail address ... 
    emails: [{ 
     // ... with the actual email address ... 
     value: String, 
     // ... and the type of email address (home, work, etc.). 
     type: String 
    }], 
    // A unique identifier for the user, as generated by the service provider. 
    id: String, 
    // The name ... 
    name: { 
     // ... with the family name of this user, or "last name" in most Western languages ... 
     familyName: String, 
     // ... with the given name of this user, or "first name" in most Western languages ... 
     givenName: String, 
     // ... and with the middle name of this user. 
     middleName: String 
    }, 
    // The provider which with the user authenticated. 
    provider: String 
}); 

Các e -mail có một thuộc tính được gọi là 'loại', được dành riêng cho loại mongoose. Tôi giải quyết điều này như thế nào?

Trả lời

73

Bạn cần phải xác định lĩnh vực này sử dụng một đối tượng:

type: {type: String} 
+0

Cảm ơn! Tôi sẽ chấp nhận câu trả lời khi giới hạn thời gian cho phép tôi. Một câu hỏi không liên quan, mảng e-mail bây giờ có một trường _id mà tôi không muốn. Có sửa chữa nhanh/dễ dàng không? –

+1

@RoelvanUden Xem câu trả lời cho câu hỏi này: http://stackoverflow.com/questions/12617754/mongoose-js-3-how-to-tell-that-nested-is-not-a-document/12621311#12621311 – JohnnyHK

Các vấn đề liên quan