Date type in Cashbah

MongoDB的Scala Driver: Cashbah提供了便利的方法来生产正确格式的时间格式:

参考: 3.2. Briefly: Automatic Type Conversions <- Tutorial: Using Casbah <http://mongodb.github.io/casbah/tutorial.html#briefly-automatic-type-conversions>

def prjData =
  for (task <- mpx.getAllTasks.toList) {
    if (task.getName != null) {
      val taskItem = MongoDBObject(
        "UniqueID" -> task.getUniqueID,
        "Name" -> task.getName,
        "OutlineNum" -> task.getOutlineNumber,
        "ResourceName" -> resourceName(task),
        "StartDate" -> new DateTime(task.getStart),
        "FinishDate" -> new DateTime(task.getFinish),
        "Duration" -> duration(task),
        "PercntComplete" -> task.getPercentageComplete)
      mongoCollection += taskItem
    }
  }

===

查询时间类型数据:

db.plan.find(
    { 'StartDate' : { 
        '$gt' : ISODate('2013-12-01T00:00:00Z'), 
        '$lt' : ISODate('2013-12-29T00:00:00Z') } 
    }
)

你可能感兴趣的:(Date type in Cashbah)