[英]$and in reactive mongo with play framework 2.6
我正在使用带有scala的play framework v2.6,我正在使用reactmongo作为mongodb的驱动程序,我的问题是我不知道如何检索具有两个值之间的值的对象。在我的示例中,我有这个case类:
case class Card (id : String, creationDate: Date)
我想检索具有两个日期之间的创建日期的卡片,因此我使用了以下查询:
val query = BSONDocument(
"$and" -> BSONDocument(
"creationDate" -> Json.obj("$gte" ->startDate),
"creationDate" -> Json.obj("$lte" ->endDate))
)
但这会输出以下错误:
A server error occurred DatabaseException['Can't canonicalize query:
BadValue and needs an array' (code = 17287)]
根据mongo文档 , $and
运算符需要一个数组:
val query = BSONDocument(
"$and" -> BSONArray(List(
BSONDocument("creationDate" -> Json.obj("$gte" ->startDate)),
BSONDocument("creationDate" -> Json.obj("$lte" ->endDate))
))
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.