【发布时间】:2017-12-11 16:44:20
【问题描述】:
我有集合 user、news 和 user-news。“user-news”填充到“user”和“news”。
我可以按“user.name”或“news.title”对“user-news”的文档进行排序和搜索吗?
const usersSchema = new Schema({ name: String })
const newsSchema = new Schema({ title: String }),
UsersNewsModel.find(queryObj)
.populate('user', 'name')
.populate('news', 'title')
.sort({ 'user.name': -1 })
.exec((findError, records) => {...}
【问题讨论】:
标签: node.js mongodb express mongoose