2017-06-09 5 views
1

Je suis coincé ici pour écrire le schéma de mongoose pour événements et champs d'anniversaires. J'utilise mongodb/mangouste et voudrais enregistrer le contenu similaire dans événements collections.Schéma Mongoose pour les tableaux et les hachages

{ 
"_id" : ObjectId("5938fc171dfe0f225902d85d"), 
"month" : 6, 
"date" : 9, 
"happenings" : [ 
    { 
     "incident" : "Muhammad, the founder of Islam and unifier of Arabia, died.", 
     "year" : "632" 
    }, 
    { 
     "incident" : "The Army of the Potomac defeats Confederate forces at Battle of Cross Keys, Virginia..", 
     "year" : "1862" 
    }, 
    { 
     "incident" : "Israeli airplanes attack the USS Liberty, a surveillance ship, in the Mediterranean, killing 34 Navy crewmen..", 
     "year" : "1967" 
    }, 
    { 
     "incident" : "Gemini astronaut Gene Cernan attempts to become the first man to orbit the Earth untethered to a space capsule, but is unable to when he exhausts himself fitting into his rocket pack.", 
     "year" : "1966" 
    } 
], 
"birthdays" : { 
    "actor" : { 
     "name" : "Josh Pence", 
     "yob" : 1982, 
     "birthplace" : "Santa Monica, CA", 
     "role" : "MOVIE ACTOR", 
     "image" : "josh_1982.png" 
    }, 
    "actress" : { 
     "name" : "Julianna Margulies", 
     "yob" : 1966, 
     "birthplace" : "Spring Valley, NY", 
     "role" : "TV ACTRESS", 
     "image" : "julianna_1966.png" 
    }, 
    "player" : { 
     "name" : "Julianna Margulies", 
     "yob" : 1987, 
     "birthplace" : "Ohio", 
     "role" : "FOOT BALL", 
     "image" : "julianna_1966.png" 
    } 
} 

}

Le schéma que j'ai essayé

var schema = new Schema({ 
    day: Number, 
    Month: Number, 
    birthdays: Schema.Types.Mixed, 
    happenings: [], 
    incident: [String], 
    year: [Number], 
}) 


var event= mongoose.model('Event', schema); 

Comment dois-je modifier le schéma ci-dessus ??

Répondre

1

Selon votre document, je pense que votre schéma pourrait être comme

var schema = new Schema({ 
    day: Number, 
    Month: Number, 
    birthdays: Schema.Types.Mixed, 
    happenings: [{ 
    incident: String, 
    year: String, 
    _id: false 
    }] 
}); 

var event= mongoose.model('Event', schema);