跳到主內容

常用指令

使用mongosh 連入db

srou@momo-full-devdeiMac ~ % mongosh
Current Mongosh Log ID:	63de0489619b4a08812f03ee
Connecting to:		mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.6.2
Using MongoDB:		6.0.4
Using Mongosh:		1.6.2

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

------
   The server generated these startup warnings when booting
   2023-02-04T06:35:33.363+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
   2023-02-04T06:35:33.363+00:00: vm.max_map_count is too low
------

test> 

 

db.order.aggregate([
  	{ 	$match : {
    		liveId: "aaaa",
      		orderDate: { $gt:ISODate("2023-11-01T23:00:00+08:00")}
    	}
    },
    {
        $group: {
            _id: {
                orderNo: "$orderNo",
                liveId: "$liveId"
            },
            count: { $sum: 1 }
        }
    },
    {
        $match: {
            count: { $gte: 2 }
        }
    },
  {
    $sort: { count : -1}
  },
  {
  	$limit:5
  }
])
/////////////////////////////////////////
select count(orderNo), count(liveId) 
from order 
group by orderNo, liveId 
order by count(liveId)
having count(*) >= 2
limit 5