Pergunta

The Strongloop Loopback documentation does not say anything about object retrieval using bitwise filters.

Example like in Loopback API documentation :

// Just an example of syntax, it does not do bitwise filter
Inventory.find({where: {status: {gt: 4}});

With a direct connection to MongoDB, I can do :

// Select items with 3rd bit on in `status` field
db.inventory.find({status: {$mod: [4, 0]}});

Can I do the same behind Loopback model interface ?

In MongoDB docs they say that a $were condition can do the same, while more expensive :

db.inventory.find( { $where: "this.qty % 4 == 0" } )

Could I be doing the following in loopback :

Inventory.find({where: "this.qty % 4 == 0"});

Or it would fail ?

Is the whole idea of using a bitwise-oriented status field in my model overkill ? Should I just use some kind of array field containing a list of string status ? Isn't it too expensive in terms of DB storage ?

Thanks

Foi útil?

Solução

LoopBack uses similar JSON object as MongoDB to describe a query. Please keep in mind that LoopBack supports multiple databases such as MongoDB, MySQL, and Oracle. Ideally, the operator should be supported by all of them. LoopBack connectors map it into native queries.

We don't support bitwise operators for all the connectors yet. But for MongoDB, we pass through the operators by adding a $. For example, {mod: [ 4, 0 ]) becomes $mod: [ 4, 0 ].

Please open an issue. We'll follow up there.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top