【发布时间】:2019-02-05 05:39:45
【问题描述】:
我刚刚阅读了How to query the string field value length in MongoDB 并在直接在 MongoDB 控制台中使用时成功获得了一个查询。我使用的查询是:
db.getCollection('language').find({
name: {$ne: ''},
$where: "this.i18n.length < 3"
})
我现在正尝试在 Yii2 中复制相同的内容:
$languages = Language::find()
->where(['$ne', 'name', ''])
->andWhere(['<', 'this.i18n.length', '3'])
->all();
但是数组是空的。
我试过没有字符串长度的查询:
$languages = Language::find()
->where(['$ne', 'name', ''])
->all();
并且数组被填充。
我也尝试过单独使用字符串长度的查询:
$languages1 = Language::find()
->where(['<', 'this.i18n.length', '3'])
->all();
$languages2 = Language::find()
->where(['<', 'i18n.length', '3'])
->all();
但数组仍然是空的。
问题是:如何让$where: "this.i18n.length < 3" 在 Yii2 中工作?
【问题讨论】:
标签: mongodb yii2 yii2-active-records