基本的には、変数nestedDov
を作成し、簡易版ここname: [nestedDov]
をそれを置く:
var nestedDoc = new Schema({
name: String
});
var mainDoc = new Schema({
names: [nestedDoc]
});
JSON例
{
"_id" : ObjectId("57c88bf5818e70007dc72e85"),
"name" : "Corinthia Hotel Budapest",
"stars" : 5,
"description" : "The 5-star Corinthia Hotel Budapest on the Grand Boulevard offers free access to its Royal Spa",
"photos" : [
"/photos/hotel/corinthiahotelbudapest/1.jpg",
"/photos/hotel/corinthiahotelbudapest/2.jpg"
],
"currency" : "HUF",
"rooms" : [
{
"type" : "Superior Double or Twin Room",
"number" : 20,
"description" : "These are some great rooms",
"photos" : [
"/photos/room/corinthiahotelbudapest/2.jpg",
"/photos/room/corinthiahotelbudapest/5.jpg"
],
"price" : 73000
},
{
"type" : "Deluxe Double Room",
"number" : 50,
"description" : "These are amazing rooms",
"photos" : [
"/photos/room/corinthiahotelbudapest/4.jpg",
"/photos/room/corinthiahotelbudapest/6.jpg"
],
"price" : 92000
},
{
"type" : "Executive Double Room",
"number" : 25,
"description" : "These are amazing rooms",
"photos" : [
"/photos/room/corinthiahotelbudapest/4.jpg",
"/photos/room/corinthiahotelbudapest/6.jpg"
],
"price" : 112000
}
],
"reviews" : [
{
"name" : "Tamas",
"id" : "/user/tamas.json",
"review" : "Great hotel",
"rating" : 4
}
],
"services" : [
"Room service",
"Airport shuttle (surcharge)",
"24-hour front desk",
"Currency exchange",
"Tour desk"
]
}
例:
私はこれに答えをタイプしようとしていましたが、どうやって見つけられませんでした。しかしここで見てください:http://mongoosejs.com/docs/subdocs.html – gustavohenke
MongoDBのデータベーススキーマの作成時にあなた自身に尋ねる良い答えは、http:// stackoverflowです。com/questions/5373198/a-simple-mongodb-question-embed-or-reference – anthonylawson
あなたは '_id'フィールドについても記述する必要がありますか?それが有効になっていれば、それは自動的なものではありませんか? – Vadorequest