本人是菜鸟,练习的时候遇到了一个问题, 假如我有两张表,Author和Book,现在我想做一下模糊查询,通过一个关键字name_ 来查找Book的name like name_ 或者Book.Author.name like name_
对于嵌入式的文档模型关系我可以这么做: var User = mongoose.Schame({ name :String , author : { name :String } }); var reg = new Regex(name_ , ‘g’); User.find({$or:{name : reg,author.name :reg}}).exec();
但是为了独立表结构,实际ref模型如下: var User = mongoose.Schame({ name :String , author : { type :ObjectId, ref :’author’ } }); var Author = mongoose.Schame({ name : String , books : [{ type : ObjectId , ref :’book’ }] });
求:独立表怎样进行关联查询