SailsJS with MongoDB adapter not working as expected. I have following relations defined:
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'
}
}
};
When I query without criteria and populate categories
like:
Post.find()
.populate('categories')
.then(...)
it gives me correct result, the document has categories nested.
But when I try to pass criteria it returns no result. e.g.
Post.find({categories: 'food'})
.populate('categories')
.then(...)
Note: I inserted category _id
as string (food, travel, etc) in database
Please help