【发布时间】:2015-10-26 07:52:28
【问题描述】:
带有 MongoDB 适配器的 SailsJS 无法按预期工作。我定义了以下关系:
Post.js:
module.exports = {
connection: 'mongodb',
attributes: {
title: 'string',
categories: {
collection: 'postCategory',
via: 'posts'
}
}
};
PostCategory.js
module.exports = {
connection: 'mongodb',
attributes: {
name: 'string',
posts: {
collection: 'post',
via: 'categories'
}
}
};
当我在没有条件的情况下查询并填充categories 时:
Post.find()
.populate('categories')
.then(...)
它给了我正确的结果,文档有嵌套的类别。
但是当我尝试通过标准时,它不会返回任何结果。例如
Post.find({categories: 'food'})
.populate('categories')
.then(...)
注意:我在数据库中插入了类别_id 作为字符串(食物、旅行等)
请帮忙
【问题讨论】:
标签: mongodb sails.js sails-mongo