【问题标题】:Can I use bitwise operators to request a Loopback model?我可以使用按位运算符来请求 Loopback 模型吗?
【发布时间】:2014-09-30 21:41:25
【问题描述】:

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]}});

我可以在 Loopback 模型接口后面做同样的事情吗?

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

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

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

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

或者它会失败?

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

谢谢

【问题讨论】:

    标签: node.js mongodb bit-manipulation strongloop loopbackjs


    【解决方案1】:

    LoopBack 使用与 MongoDB 类似的 JSON 对象来描述查询。请记住,LoopBack 支持多种数据库,例如 MongoDB、MySQL 和 Oracle。理想情况下,操作员应该得到所有人的支持。 LoopBack 连接器将其映射到本机查询。

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

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

    【讨论】:

    • 关于 mongodb 的好东西,谢谢。我确实打开了一个功能请求,所以你们可以跟进其他数据源。
    猜你喜欢
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    • 2014-10-25
    • 2011-12-09
    • 2017-10-23
    • 1970-01-01
    • 2016-10-01
    • 1970-01-01
    相关资源
    最近更新 更多