Mongodb Mongo查询将“EEE,d MMM yyyy HH:mm:ss Z”转换为yyyy mm dd

Mongodb Mongo查询将“EEE,d MMM yyyy HH:mm:ss Z”转换为yyyy mm dd,mongodb,Mongodb,我需要将日期转换为2016年10月17日星期一09:00:00 IST至2016年10月17日的格式 db.collection.aggregate( [ { $project: { yearMonthDayUTC: { $dateToString: { format: "%Y-%m-%d", date:new Date("Mon Oct 17 09:00:00 IST 2016") } } } }] ) 我的问题是这样的: db.collection.aggregate( [ { $proj

我需要将日期转换为2016年10月17日星期一09:00:00 IST至2016年10月17日的格式

db.collection.aggregate( [ { $project: { yearMonthDayUTC: { $dateToString: { format: "%Y-%m-%d", date:new Date("Mon Oct 17 09:00:00 IST 2016") } } } }] )
我的问题是这样的:

db.collection.aggregate( [ { $project: { yearMonthDayUTC: { $dateToString: { format: "%Y-%m-%d", date:new Date("Mon Oct 17 09:00:00 IST 2016") } } } }] )
如何通过mongo查询实现这一点
请帮帮我。

请使用dateToString进行合计并检查

db.collection.aggregate( [ { $project: { yearMonthDayUTC: { $dateToString: { format: "%Y-%m-%d", date:new Date("Mon Oct 17 09:00:00 IST 2016") } } } }] )
例如:$date是您要转换的日期

db.collection.aggregate( [ { $project: { yearMonthDayUTC: { $dateToString: { format: "%Y-%m-%d", date:new Date("Mon Oct 17 09:00:00 IST 2016") } } } }] )
db.Collection.aggregate(
   [
     {
       $project: {
          yearMonthDayUTC: { $dateToString: { format: "%Y-%m-%d", date: "$date" } }
       }
     }
   ]
)

请分享你所做的尝试far@BlackBeard我的查询类似于db.collection.aggregate[{$project:{yearMonthDayUTC:{$dateToString:{格式:%Y-%m-%d,日期:new DateMon 10月17日09:00:00 IST 2016}}]每次返回1970-01-01,与bson字符串日期无关我尝试了此操作..这给出了一个错误供参考我假设此Mon Oct 17 09:00:00 IST 2016为字符串,但不是ISODate,我想将此字符串转换为日期YYYY mm DD错误消息为errmsg:无法从bson类型字符串转换为日期,第一次使用new DateMon 10月17日09:00:00 IST 2016转换到日期,而不是使用$DateToString格式化日期,但当我尝试使用java驱动程序进行聚合时,它给出了错误的请求,看起来像是它的java问题。请提供准确的错误以便帮助。