【发布时间】:2014-12-20 01:55:50
【问题描述】:
我正在尝试将一个新的 Date 值制作成 reactmongo 聚合管道中的投影。
我见过人们在 mongo shell 中创建它的其他示例,如下所示:
db.runCommand({
"aggregate" : "collectionName", "pipeline": [
{ $project: { exampleDate: new Date() } }
]
})
问题在于new Date()。使用 reactivemongo,投影将是一个 Project 对象:
Project( ("exampleDate", BSONValue) )
其中 BSONValue 可以是 BSONString。但这会导致 mongoDB 忽略此类字符串,因为结果将是:
{ "aggregate" : "collectionName", "pipeline": [ { $project: { exampleDate: "new Date()" } } ] }
有什么方法可以插入不带引号的new Date()?
P.S.:我也试过使用BSONDateTime(0)
但这会导致:
{ $date: 0 }
这使得 mongoDB 抛出一个无效的 $date 运算符异常。
【问题讨论】:
标签: mongodb scala reactivemongo