안녕하세요 저는 NodeJS와 MongoDB로 phorum을 구축하고 있습니다. 정말이 tecnologies와 새로운 임, 나는 몇 가지 질문이 있습니다. 내가 buid이 내 마음에 현재 스키마가 있습니다. 이 답변이 주제를 가지고 범주가 지역,,, 위치 :몽구스 + NodeJS Phorum 스키마
var Phorum = [
{
position: 1,
name: [
{
lang: 'es',
value: 'Ideas'
}
],
categories: [
{
position: 1,
name: [
{
lang: 'es',
value: 'Interfaz visual'
}
],
topics: [
{
createdAt: 'xxx',
updatedAt: 'xxx',
userId: 123,
status: 1,
spam: false,
views: 42,
likes: [321,231],
details: [
{
lang: 'es',
title: {
normal: 'Tengo una pregunta',
url: 'tengo-una-pregunta'
},
text: {
original: 'El texto...',
formated: 'El texto...' // Esta con los enlaces y todo reemplazado
},
tags: ['tag1', 'tag2']
}
],
answers: [
{
createdAt: 'xxx',
updatedAt: 'xxx',
likes: [231, 321],
text: [
{
lang: 'es',
createdAt: 'xxx',
original: 'Respuesta...',
formated: 'Respuesta...' // Con enlaces, videos,... formateado
}
]
}
]
}
]
}
]
}
];
가 embedings 문서가 있습니다, 그리고 코드에서 나는 같은 것을 넣어 :
var mongoose = require('mongoose'),
Schema = process.DB.Schema,
ObjectId = process.DB.ObjectId;
/*
* ESQUEMA DE LOS DETALLES DE UN TEXTO
* Se usa en las respuestas y en los topics
*/
var textSchema = new Schema({
createdAt: {type: String, default: Date.now},
original: String,
formated: String
});
/*
* ESQUEMA DEL TEXTO DE UNA RESPUESTA
*/
var TextAnswerSchema = new Schema({
lang: {type: String, required: true, trim: true, lowercase: true},
text: [textSchema]
});
// Esquema de las respuestas
var AnswersSchema = new Schema({
createdAt: {type: Date, default: Date.now},
likes: {type: [ObjectId], ref: 'User', unique: true},
text: [TextAnswerSchema]
});
// Esquema de los detalles de un topic
var DetailsTopicSchema = new Schema({
lang: {type: String, required: true, trim: true, lowercase: true},
title: {
original: String,
url: String
},
text: [textSchema],
tags: {type: [String], unique: true, trim: true}
});
// Esquema para un topic
var TopicsSchema = new Schema({
createdAt: {type: Date, default: Date.now},
//userId: {type: ObjectId, ref: 'User'},
userId: {type: Number},
status: {type: Number, default: 1, min: 1, max: 3},
spam: {type: Boolean, default: false},
views: {type: Number, default: 0, min: 0},
//likes: {type: [ObjectId], ref: 'User', unique: true},
details: [DetailsTopicSchema],
answers: [AnswersSchema]
});
// Detalles de los nombres de una categoria
var DetailsNameSchema = new Schema({
lang: {type: String, required: true, trim: true, lowercase: true},
value: {type: String, trim: true}
});
// Esquema de las categorias
var CategoriesSchema = new Schema({
position: {type: Number, default: 9999},
name: [DetailsNameSchema],
topics: [TopicsSchema]
});
// La estructura de la coleccion tracker
var AreasSchema = new Schema({
position: {type: Number, default: 9999},
name: [DetailsNameSchema],
categories: [CategoriesSchema]
});
// Exponemos los modelos
// Guardamos en los modelos de mongoose
mongoose.model('AreasSchema', AreasSchema);
mongoose.model('CategoriesSchema', CategoriesSchema);
mongoose.model('DetailsNameSchema', DetailsNameSchema);
mongoose.model('TopicsSchema', TopicsSchema);
mongoose.model('DetailsTopicSchema', DetailsTopicSchema);
mongoose.model('AnswersSchema', AnswersSchema);
mongoose.model('TextAnswerSchema', TextAnswerSchema);
mongoose.model('textSchema', textSchema);
을하지만 난 사용할 때 "mongoose.model ('abc', abc);" 몽구스 컬렉션을 만듭니다. 나는 하나의 컬렉션만을 원한다. 왜냐하면 나는 이것을 더 좋고, 더 효율적이라고 읽었 기 때문이다.
큰 JSON 개체가있는 컬렉션을 원한다면 어떤 주제를 읽을 수 있습니까? 이런 식으로 뭔가 :
AreaModel.find({'categories.topics.id': 'xxx'}, function(){})
그러나, 그 추적 할 수없는 가망이 카테고리 ID가없는 주제 ID에 찾아 가서?
아마 내 스키마가 잘못되었습니다. 감사합니다.