db.customer_poster.find().forEach( function(res){
print("poster_id:",res.poster_id);
if (res.update_time instanceof Date){
var updateTime=res.update_time.getTime();
updateTime=updateTime/1000;
updateTime=parseInt(updateTime);
res.update_time=NumberLong(updateTime);
db.customer_poster.save(res);
} } )
上面这段shell执行的操作就是把customer_poster中update_time改为时间戳存储。
执行结果如图所示。
类型判断:res.update_time instanceof Date
类型判断instanceof用法参考:https://www.jinmuinfo.com/community/MongoDB/docs/03-mongo/04-shell-types.html