javascript - Waterline (Sails.js): AND conditions -
i'm using mongodb sails.js querying model contains titles of torrent files. i'm not able perform waterline query using "and" condition. i've tried in several ways of them return empty or simply, never return.
e.g. database contains entry with: "title": "300 rise of empire 2014 720p bluray x264-blow [subs spanish latino] mkv"
when adding each query parameter line 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" } } ] }); it returns entries containing "2014" , ("720p" or "1080p"), of them contain "spanish" think it's coincidence.
how can specify "spanish" , "2014" , ("720p" or "1080p)?
thanks!
there solution it's mongo 1 :
query = query.where({"$and": [ { "title": { "contains": "720p" } }, { "title": { "contains": "1080p" } } ] }); notice $and key?
from sails-mongo source :
/** * parse clause * * <clause> ::= { <clause-pair>, ... } * * <clause-pair> ::= <field> : <expression> * | or|$or: [<clause>, ...] * | $or : [<clause>, ...] * | $and : [<clause>, ...] * | $nor : [<clause>, ...] * | : { <field>: <expression>, ... } * * @api private * * @param original * @returns {*} */
Comments
Post a Comment