推荐工具
RoboMongo
推荐书目
50 Tips and Tricks for MongoDB Developers
Related Blogs
Snail in a Turtleneck
knowckx
V2EX  ›  MongoDB

Mongo 的普通查询可以转换 unix 时间戳吗?

  •  
  •   knowckx · Sep 25, 2018 · 4942 views
    This topic created in 2800 days ago, the information mentioned may be changed or developed.
    数据列有一字段是 "updatetime", 里面都是 unix 时间戳
    普通的查询语句
    db.getCollection("mg_result_sorted_all").find({},
    {
    "login": 1,
    "updatetime":1
    })

    怎么返回类似"2018-05-04 12:00:00" 这样的数据呢?
    6 replies    2018-09-25 16:09:38 +08:00
    knowckx
        1
    knowckx  
    OP
       Sep 25, 2018
    mysql 就很简单了……
    直接 select 里套一个 time 格式化函数就好了… mongo 的不知道怎么做
    yulitian888
        2
    yulitian888  
       Sep 25, 2018   ❤️ 1
    new Date(时间戳)
    knowckx
        3
    knowckx  
    OP
       Sep 25, 2018
    @yulitian888
    可能理解错意思了哦,
    不是查询时 where 里的条件,
    我想的是查询的时候可以把原始数据以"2018-05-04 12:00:00"这样的格式返回
    rbe
        4
    rbe  
       Sep 25, 2018
    $aggregate 的 $group 里面的运算符应该可以满足需求,比如 $dateToString 之类的
    不过感觉没啥必要啊,可以查出来以后再做转换呀
    rbe
        5
    rbe  
       Sep 25, 2018
    不好意思哈 是 $project
    yulitian888
        6
    yulitian888  
       Sep 25, 2018   ❤️ 1
    @knowckx 查出来再转就是了
    db.getCollection("mg_result_sorted_all").find({}).forEach(function (a) { /*这里转吧!*/ });
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3282 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 11:46 · PVG 19:46 · LAX 04:46 · JFK 07:46
    ♥ Do have faith in what you're doing.