mongodb基本语法

查询
where 查询:

db.getCollection("xxxx").find({"id":NumberLong('11111111111')}).limit(10)

查询表行数

db.getCollection("xxxx").count()

查询某age和sex列,过滤条件,并且把sex列的列名改成性别:

db.getCollection("xxxx").aggregate(
 [
 	{
        "$match": {
         	"sex": "男",
            "category": {
                "$in": ["数学", "语文"]
            },
            'fieldName': {exists: true, $ne: null },
            'createTime': {
                    $gte: ISODate('2022-07-01T00:00:00Z'),
                    $lte: ISODate('2022-08-01T00:00:00Z')
                },
        }
    },
    { "$project": {
       "_id": 0,
	   "age": 1,
	   "性别": "$sex",
	   "生日":{$dateToString:{format:"%Y-%m-%d",date:"$birth"}},
	   "number": "$number",
	   "时间": ""
    }},
    //查询前10条
    { $limit: 10 },
    //如果想分组,就写下面这个group
    ,{
            "$group": {
                "_id": "$colname",//分组字段
                "number": {
                    $avg: "$age"
                }
            }
        }
]);

新增
单个修改

批量修改

db.getCollection("table").update({"aaa":"0108"},{$set:{"bbb":"360"}},{multi: true});

删除

创建视图

db.createView("view_name", "collection_name", [
    {
        $match: {
            abc: "2109245374"
        }
    },
    {
        $project: {
            _id: 1,
            abc: 1,
            def: 1
        }
    }
])
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值