Tuesday, 15 February 2011

Waterline/Sails.js/Mongo How to use AND conditions in query for one filed? -



Waterline/Sails.js/Mongo How to use AND conditions in query for one filed? -

my question same waterline (sails.js): , conditions. there reply it's not work me (neither questioner).

as far know , waterline doesn't have keyword 'and' in query language. if have multiple conditions query, can use:

mymodel.find({fielda:valuea, filedb:valueb});

but question how do:

mymodel.find({fielda:{ contains:keyword1, contains:keyword2 }});

for can't set 2 key same name in object/json, tried :

mymodel.find({fielda: [ {contains:keyword1}, {contains:keyword2} ] });

and

mymodel.find({fielda: {contains:[keyword1,keyword2]} });

and

mymodel.find() .where({fielda:{contains:keyword1}) .where({fielda:{contains:keyword2}});

but none of them work expected : 1st , 2nd 1 returns empty set , 3rd 1 contains keyword2. appears when trying add together 2 'contains' status same filed(fielda), chained 'where' method, sec 1 overwrite first one.

i'm using native mongodb's way handle workaround, dose know how in waterline's way ? or issue should reported on github.

ps:sorry poor english language :p

to reply question, multiple contains not supported. whether it's omission or feature request debatable. @ to the lowest degree sql case, it's stupid simple prepare (though took me on hr find it) able back upwards like:

orm.collections.user.find({ and: [ { name: { contains: 'neil' } }, { name: { contains: 'armstrong' } } ] });

all needs case 'and': in in next file , works:

https://github.com/balderdashy/waterline-sequel/blob/master/sequel/lib/criteriaprocessor.js#l120

i suspect mongo case similar.

sails.js waterline

No comments:

Post a Comment