function getDateTime(time) {
var date = new Date(time);
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
var hh = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var mm = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var ss = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
return date.getFullYear() + "-" + month + "-" + currentDate+" "+hh + ":" + mm+":"+ss;
}
db.getCollection('exam_define').find({"obj_type":1,"agency_id":11}).forEach(function(doc){
var time_is_number = isNumber(doc.create_time);
var old_time = doc.create_time;
var update_time = doc.update_time;
if (time_is_number) {
var createTime = getDateTime(old_time*1000);
var updateTime = getDateTime(update_time*1000);
db.getCollection('exam_define').update({"_id":doc._id},{$set:{"create_time":createTime,"update_time":updateTime}},false,false);
}
});
db.exam_define.aggregate([
{$match:{"_id":ObjectId("622db8327b3788180f40b984")}},
{$unwind:"$arr_item"},
{$lookup:{"from":"exercise","localField":"arr_item.d_id","foreignField":"id","as":"exercise"}},
{$unwind:"$exercise"},
{$match:{"exercise.status":-1}}
]).forEach(function(doc){
db.getCollection('exam_define').update({"_id":doc._id},{$pull:{"arr_item":{"d_id":doc.arr_item.d_id}}},false,false);
var rows = db.getCollection('exam_define').find({"_id":doc._id});
var currItem = rows[0].arr_item;
var json_item = JSON.stringify(currItem);
var question_count = currItem.length;
db.getCollection('exam_define').update({"_id":doc._id},{$set:{"json_item":json_item,"question_count":question_count}},false,false);
})
将mongodb中的时间戳转为日期时间
于 2022-03-28 17:21:39 首次发布