如何在 Mongoose with Feathers/Vue 堆栈中对查询使用验证?这就是我正在经历的。传递给 feathers-mongoose 服务的任何查询条件都必须在 Vue 模型中传递,以便它运行查询,过滤掉没有名称属性或根本没有字段的返回项。这是它不起作用时的样子。注意“真实”的结果。
var vm = new Vue({
el: '#app',
data () {
return {
places:[]
}
},
ready () {
// Find all places
placeService.find({
query: {
** name: { $exists: true } **
}
}).then(page => {
this.places = page.data
})
}
})
如果您将其添加到服务的“选项”中,则查询最终会显示在 index.html 的 {{ i.name }} 中显示为“true”的项目。这是服务设置:
module.exports = function() {
const app = this;
const options = {
Model: place,
paginate: {
default: 15,
max: 30
},
// query: {
// name: { $exists: true },
// city: { $exists: true }
// }
};
// Initialize our service with any options it requires
app.use('/places', service(options));
另一个注意事项,如果您尝试使用来自视图模型的内置验证功能
$select: { name: { $exists: true }}
如下所示,或通过添加
{$exists:true}
对于 mongoose 模型,您将获得与在 feathers-mongoose 选项中运行它相同的结果。
ready () {
// Find all places
placeService.find({
query: {
$select: { name: { $exists: true }}
}
}).then(page => {
this.places = page.data
})
}
谢谢你。