【问题标题】:How do you do with sailsjs a query with '$in'你如何使用sailsjs 使用'$in' 进行查询
【发布时间】:2014-02-14 16:17:39
【问题描述】:

我有一个收藏:

{name : 'hello', tags : ['foo', 'bar']}
,{name : 'world', tags : ['space', 'bar']}
,{name : 'galaxy', tags : ['foo', 'space']}

    ,attributes: {
        ,name: {
            type: 'STRING'
            ,required : 'string'
        }

        ,tags: {
            type: 'ARRAY'
            ,required : 'array'
        }
    }


};

我尝试过,但它不起作用:

myCollection.find().where({tags: ['space' ,'foo']});s

如何搜索具有特定标签的所有项目?

谢谢你

【问题讨论】:

标签: javascript node.js sails.js


【解决方案1】:

Waterline 将myCollection.find().where({tags: ['space' ,'foo']}); 解释为“查找所有标记为'space', 'foo'一个 的位置”;它不做花哨的数组交集。为此,您需要访问本机适配器方法。假设您使用的是 Mongo,它将是:

myCollection.native(function(err, collection) {

   collection.find({tags:{'$in':['space','foo']}}).toArray(function(err, results) {

     // Do something with results

   });

});

关于原生 Mongo 适配器 here 的文档。

【讨论】:

    猜你喜欢
    • 2014-11-19
    • 2021-11-07
    • 1970-01-01
    • 2013-12-13
    • 1970-01-01
    • 1970-01-01
    • 2016-03-01
    • 2018-08-18
    • 1970-01-01
    相关资源
    最近更新 更多