这是我的数据结构,我想实现一个关系查询,但是查询的是嵌套数据字段。我看了mongoose文档后知道嵌套查询的基本用法,但是当我测试时却没有返回。请帮助我,我会感激的。
//Define
var TimeLine = new keystone.List('TimeLine', {
hidden:true
});
TimeLine.add({
article:{type:Types.Relationship,ref:'Post'}
});
var Post = new keystone.List('Post', {
map: { name: 'title' },
autokey: { path: 'slug', from: 'title', unique: true }
});
Post.add({
title: { type: String, required: true },
state: { type: Types.Select, options: 'draft, published, archived', default: 'draft', index: true },
author: { type: Types.Relationship, ref: 'User', index: true },
publishedDate: { type: Types.Date, index: true, dependsOn: { state: 'published' } },
image: { type: Types.CloudinaryImage },
content: {
brief: { type: Types.Html, wysiwyg: true, height: 150 },
extended: { type: Types.Html, wysiwyg: true, height: 400 }
}
});
//Usage
var timeline = keystone.list('TimeLine').model;
timeline.find({
"article.title":"xxxxxxxxx"//Here is a nested query
}).populate('article').exec(function (err, result) {
console.log(err,result);//This is the query results, but it can not return anything.
});
//nothing return!!!