Dynogels:使用OR比较的查询

我正尝试将以下scans优化为单个scan (或query )。 我看到的唯一方法是使用DynamoDB使用OR比较器 。 我在我的应用程序中使用dynogels (fork of vogels ),但遗憾的是我没有意识到任何OR查询function。

 let arrivals = yield Reservation.scan() .where('room').equals(room) .where('arrival').between(from, to) .execAsync().then((reply) => reply.Items.map((item) => item.get())); let departures = yield Reservation.scan() .where('room').equals(room) .where('departure').between(from, to) .execAsync().then((reply) => reply.Items.map((item) => item.get())); let combined = arrivals.concat(departures); return Promise.resolve(combined); 

build议的优化:

 return Reservation.scan() .where('room').equals(room) .where('arrival').between(from, to) .or.where('departure').between(from, to) .execAsync().then((reply) => reply.Items.map((item) => item.get())); 

扫描得到在指定的date范围( fromto )结束( departure )或开始( arrival )(或两者)的保留。

我认为这可以使用filterexpression来实现。

使用filterexpression的示例代码: –

 const scanItem = Reservation.scan().filterExpression('room = :idVal AND ((arrival BETWEEN :arrDateVal1 AND :arrDateVal2) OR (departure BETWEEN :depDateVal1 AND :depDateVal2)) ') .expressionAttributeValues({ ':idVal' : '2', ':arrDateVal1' : '21-APR-2017', ':arrDateVal2' : '23-APR-2017' ,':depDateVal1' : '21-APR-2017', ':depDateVal2' : '23-APR-2017'}); scanItem.exec((err, result) => {if(!err) {console.log(JSON.stringify(result,undefined, 2))}}); 

注意:-

不确定是否要专门使用where而不是filterexpression (或)只是想实现结果,无论在wherefilterexpression