朋友们,我正在尝试在我的subDoc类别字符串匹配中找到
以下是代码:
router.get('/:_categoryName', (req, res, next) => {
Malgezot.findOne({ 'items.category': req.params._categoryName }, (err, malgezot) => {
if(err) return res.render('body/category', {info: ''});
console.log(malgezot);
});
});
但结果是所有项目!
我也尝试过:
router.get('/:_categoryName', (req, res, next) => {
Malgezot.find({'items': { 'category': req.params.categoryName }}, (err, malgezot) => {
if(err) return res.render('body/category', {info: ''});
console.log(malgezot);
});
});
答案 0 :(得分:0)
如果您的数据是对象形式,则查询应为:
#!/usr/bin/env bash
if [[ -z "$TRAVIS_PULL_REQUEST_BRANCH" ]]; then
BRANCH="$TRAVIS_PULL_REQUEST_BRANCH"
else
BRANCH="master"
fi
exitcode=0
for file in $(git diff --name-only $BRANCH | grep .tf\$); do
if [[ "$(terraform fmt -write=false "$file" | wc -l)" -gt 0 ]]; then
echo "ERROR: $file failed to pass terraform fmt"
exitcode=1
fi
done
exit $exitcode
或者如果你的数据是数组形式,那么你的查询应该是:
router.get('/:_categoryName', (req, res) => {
const { _categoryName } = req.params;
Malgezot.findOne({
'items.category': _categoryName
}).then((data) => {
if (data) {
res.status(200).json(data)
}
}).catch((err) => {
res.status(500).json({
message: 'Internal server error'
});
});
});