0

Mongo describes an embedded query like this:

db.inventory.find(
    {
        producer:
        {
            company: 'ABC123',
            address: '123 Street'
        }
    }
)

Therefore I would expect a sails blueprint query for embedded docs to look like this:

http://myserver.com/blueprint/inventory?where={"producer":{"company":"ABC123","address":"123 Street"}}

But that returns an empty array. How does one use blueprints to query for embedded documents?

Cort Fritz
  • 143
  • 1
  • 5

1 Answers1

1

There's no way to do this with blueprints. In fact, there's no way to do this with generic Waterline methods, period. This exposes two important points:

  1. Blueprints are not intended as a solution to replace all business logic. They are intended to expose a simple API. If you need something more, writing a custom controller action is fun and easy. If you put it in InventoryController.js and name it find, then your /inventory endpoint will call it automatically.

  2. Waterline is an ORM meant (like all ORMs) to present a unified interface across different databases, meaning that it has to make tradeoffs in supporting specific database features (like embedded documents). If you need to query embedded documents in MongoDB, you can use the .native() method of your model to do so.

sgress454
  • 24,870
  • 4
  • 74
  • 92