我可以使用按位运算符来请求Loopback模型吗?
Strongloop Loopback文档没有提到任何有关使用按位筛选器进行对象检索的内容。
例如在Loopback API文档中 :
// 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文档中,他们说$是条件可以做同样的事情,而更昂贵 :
db.inventory.find( { $where: "this.qty % 4 == 0" } )
我可以在回送中执行以下操作:
Inventory.find({where: "this.qty % 4 == 0"});
或者它会失败?
在我的模型中使用按位导向的状态字段的整个想法是否过度? 我应该只使用某种包含string状态列表的数组字段? 数据库存储不是太昂贵吗?
谢谢
LoopBack使用与MongoDB类似的JSON对象来描述查询。 请记住,LoopBack支持多种数据库,如MongoDB,MySQL和Oracle。 理想情况下,运营商应该得到所有的支持。 LoopBack连接器将其映射到本机查询。
我们不支持所有连接器的按位运算符。 但是对于MongoDB,我们通过添加$来传递操作符。 例如, {mod: [ 4, 0 ])
变成$mod: [ 4, 0 ]
。
请打开一个问题 。 我们会在那里跟进。