如何通过数组属性查询模型 [英] How to query models by a property that is an array

查看:74
本文介绍了如何通过数组属性查询模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在具有数组属性的模型中执行"findOne"操作,并过滤结果以仅在该字符串中搜索该字符串时才列出该项目.

示例:

  var AppUser = server.loopback.getModel('AppUser');
  AppUser.create({
    "name":"juan"
    "favoriteLetters":["a","b","c"]
  },function(){
    AppUser.findOne({where:{favoriteLetters:'a'}},function(error,appUser){
      console.log(error,appUser);
    });
  });

因此在这种情况下,我想找到一个带有喜欢的字母'a'的'appUser'.

谢谢.

据我了解,这种查询的可能性取决于基础数据源,而关系型数据库尚不支持这种查询.但是应该适合内存存储或mongodb.有关查询的更多详细信息和语法,请参见: https://groups.google.com/d/msg/loopbackjs/8c8kw8EMiPU/yev3lsmrTFUJ

I'm trying to do a 'findOne' operation in a model that has an array property and filter the results to only list the item if the string im searching is in that array.

Example:

  var AppUser = server.loopback.getModel('AppUser');
  AppUser.create({
    "name":"juan"
    "favoriteLetters":["a","b","c"]
  },function(){
    AppUser.findOne({where:{favoriteLetters:'a'}},function(error,appUser){
      console.log(error,appUser);
    });
  });

So in this case i want to find a 'appUser' that has a favorite letter 'a'.

Thanks.

解决方案

As far as I understood, possibility of such kind of a query depends on the underlying datasource and is not supported yet for relational DBs. But should be fine with memory storage or mongodb. More details and syntax for query is here: https://groups.google.com/d/msg/loopbackjs/8c8kw8EMiPU/yev3lsmrTFUJ

这篇关于如何通过数组属性查询模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆