【发布时间】:2015-11-06 13:19:57
【问题描述】:
我在数据库中的会话集合看起来像
{ "_id" : ObjectId("545afeb0fb8af1531e70e762"), "sId" : "g38699im4g9fz6ri6pqd31odc0fzy6", "appId" : "c6s3ki1hgay9ntavyt8mxi54ukcfci", "events" : [ { "eType" : "untimed", "name" : "testing", "sId" : "g38699im4g9fz6ri6pqd31odc0fzy6", "st" : ISODate("2014-11-06T04:51:04Z"), "et" : ISODate("2014-11-06T04:52:44Z"), "screen" : "dummy", "data" : "{\"item\":\"immortals of meluha\",\"qty\":\"2\"}" }, { "eType" : "untimed", "name" : "testing", "sId" : "g38699im4g9fz6ri6pqd31odc0fzy6", "st" : ISODate("2014-11-06T04:51:04Z"), "et" : ISODate("2014-11-06T04:52:44Z"), "screen" : "dummy", "data" : "{\"item\":\"immortals of meluha\",\"qty\":\"2\"}" } ], "device" : { "model" : "", "mem" : "", "screen" : { "size" : "", "density" : "", "aspect" : "" } }, "network" : { "career" : "", "nType" : "" }, "location" : { "lat" : "", "long" : "" }, "user" : { "uId" : "ewkrmwyaidx5avo2adj7nh839mrzdc", "data" : "{}" }, "competetors" : [ ], "st" : ISODate("2014-11-06T04:51:04Z"), "duration" : -1, "tData" : [ ] }
我正在尝试获取介于日期范围之间的会话。 当我做类似的事情时
val query = BSONDocument("st" -> BSONDocument("$gt" -> BSONDateTime(1415229720*1000L) ) )
collection.find(query).cursor[BSONDocument].enumerate().apply(Iteratee.foreach { doc => println("found document: " + BSONDocument.pretty(doc)) })
它为我提供了数据库中的所有会话,而只有 5 个会话大于给定时期。
我也试过这样做
val query = BSONDocument("st" -> BSONDocument("$gte" -> BSONDateTime(1415228760*1000L)).add( BSONDocument("$lte" -> BSONDateTime(1415229720*1000L) ) ) )
但它没有用。
查询两个时间戳之间有“st”的会话类的正确方法是什么?
【问题讨论】:
-
为什么要将纪元 (1415229720) 乘以 1000?
标签: mongodb scala datetime bson reactivemongo