I'm trying to write a complex find query using Waterline from Sails.js. Here's a simplified example of the object that I'm doing the find on:
Basically, I want to write a query where a provided search string could be equal to the id
, be in the myArray
attribute, or be the value of myNestedObject.nestedAttribute
.
I know that I can do an or like this:
MyModel.find().where({ or: [] });
That array that is provided as the or
in the .where()
is where the matches should be added, like this:
{ id: { 'contains': searchTerm } }
How do I do a query using Waterline where I can provide a search term (searchTerm
) to see if that value is in the myArray
object? And how can I check nested attributes? I am using the sails-mongo adapter, but I'd like to not write any Mongo specific queries so that I can have all the benefits of using an ORM in the future (like if we move off Mongo or something).
It’s not possible to search within embeds using standard waterline query syntax, however you can try: