水线(Sails.js):和条件 [英] Waterline (Sails.js): AND conditions

查看:91
本文介绍了水线(Sails.js):和条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mongodb和sails.js查询包含torrent文件标题的模型。但是我无法使用AND条件执行水线查询。我已经尝试了几种方法,但大多数都是空的,或者只是,永远不会返回。

I'm using mongodb with sails.js querying a model that contains the titles of torrent files. But I'm not able to perform a waterline query using the "AND" condition. I've already tried it in several ways but most of them return empty or simply, never return.

例如。该数据库包含一个条目:
title:300崛起的帝国2014 720p BluRay x264-BLOW [Subs Spanish Latino] mkv

e.g. the database contains an entry with: "title": "300 Rise Of An Empire 2014 720p BluRay x264-BLOW [Subs Spanish Latino] mkv"

逐行添加每个查询参数时:

When adding each query parameter line by line:

var query = Hash.find();
query = query.where({ "title": { "contains": "spanish" } });
query = query.where({ "title": { "contains": "2014" } });
query = query.where({"or": [ { "title": { "contains": "720p" } }, { "title": { "contains": "1080p" } } ] });

它返回包含2014AND(720p或1080p)的条目,其中一些也包含西班牙语,但我认为这只是巧合。

It returns entries containing "2014" AND ("720p" OR "1080p"), some of them also contain "spanish" but I think it's just a coincidence.

如何指定西班牙语和2014AND(720p或1080p)?

How can I specify "spanish" AND "2014" AND ("720p" OR "1080p)?

谢谢!

推荐答案

有一个解决方案,但它真的是一个mongo一个:

There is a solution but it's really a mongo one :

query = query.where({"$and": [ { "title": { "contains": "720p" } }, { "title": { "contains": "1080p" } } ] });

注意 $和键?

来自sails-mongo来源:

From sails-mongo source :

/**
 * Parse Clause
 *
 * <clause> ::= { <clause-pair>, ... }
 *
 * <clause-pair> ::= <field> : <expression>
 *                 | or|$or: [<clause>, ...]
 *                 | $or   : [<clause>, ...]
 *                 | $and  : [<clause>, ...]
 *                 | $nor  : [<clause>, ...]
 *                 | like  : { <field>: <expression>, ... }
 *
 * @api private
 *
 * @param original
 * @returns {*}
 */

这篇关于水线(Sails.js):和条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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