首页 文章

我可以使用按位运算符来请求Loopback模型吗?

提问于
浏览
1

Strongloop Loopback文档没有说明使用按位过滤器进行对象检索 .

Example like in Loopback API documentation

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

通过与MongoDB的直接连接,我可以:

// 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 ?

在MongoDB文档中,他们说$条件可以做同样的事情,而更贵:

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

我可以在环回中执行以下操作:

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

否则会失败?

在我的模型中使用面向位的状态字段的整个想法是否过度?我应该只使用某种包含字符串状态列表的数组字段吗?在数据库存储方面不是太昂贵了吗?

谢谢

1 回答

  • 2

    LoopBack使用与MongoDB类似的JSON对象来描述查询 . 请记住,LoopBack支持多个数据库,如MongoDB,MySQL和Oracle . 理想情况下,运营商应得到所有运营商的支持 . LoopBack连接器将其映射到本机查询 .

    我们还不支持所有连接器的按位运算符 . 但对于MongoDB,我们通过添加$来传递运算符 . 例如, {mod: [ 4, 0 ]) 变为 $mod: [ 4, 0 ] .

    open an issue . 我们会在那里跟进 .

相关问题