V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
fangwenxue
V2EX  ›  问与答

mongodb 分组如何返回所有字段

  •  
  •   fangwenxue · Dec 9, 2021 · 1164 views
    This topic created in 1601 days ago, the information mentioned may be changed or developed.
    [
        {
            "$group": {
                "_id": "$username",
                "total": {"$sum": 1}
            }
        }
    ]
    

    想实现的是

    select count(*) as total, * from table group by username
    
    1 replies    2021-12-10 08:59:04 +08:00
    namidairo
        1
    namidairo  
       Dec 10, 2021
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1025 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 22:09 · PVG 06:09 · LAX 15:09 · JFK 18:09
    ♥ Do have faith in what you're doing.