В узле js mongoose Вам нужно найти описание статьи на следующих уровнях схемы. как это возможно с мангустом. Я пытался использовать $ elemMatch и не работал. уровень схемы выглядит следующим образом.узел js mongoose найти глубоко вложенные документы
var articleSchema = new Schema({
name: { type: String, required: true },
displayName: { type: String },
description: { type: String },
});
mongoose.model('Article', articleSchema);
var subChapterSchema = new Schema({
name: {type: String, required: true},
displayName: {type: String},
Articles:[articleSchema],
});
mongoose.model('SubChapter', subChapterSchema);
var chapterSchema = new Schema({
name: {type: String, required: true },
displayName: {type: String },
subChapters: [subChapterSchema],
});
mongoose.model('Chapter', chapterSchema);
var agreementSchema = new Schema({
name: {type: String, required: true },
displayName: {type: String },
Chapters: [chapterSchema],
});
mongoose.model('Agreement', agreementSchema);
Я пробовал следующим образом. Но его не работает.
var regex = new RegExp(text, "i");
var criteria = {
Chapters.subChapters.Articles : {
$elemMatch: {
description:regex
}
}
}
Agreement.find({criteria},'name displayName',function(err,docs){
if (err)
console.log('error occured in the database');
console.log(docs);
});
'подразделов: [chapterSchema]' или 'главы: [chapterSchema]' в '' agreementSchema? –
главы: [chapterSchema] –
Помните, что 'key' - это' 'главы' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' –