MongoDB操作记录

发布时间 2023-04-28 16:07:54作者: primaryC

1,经历过的坑

  1. MongoDb 内层数据,需要转换类型再过滤
db.model_18300_1_origin.aggregate([
    {
        $unwind: {
            path: "$properties"
        }
    },
    {
        $match: {
            $and: [
                {
                    "properties.name": "构件图元ID"
                },
                {
                    "properties.system": 0
                },
                
            ]
        }
    },
    {
        $project: {
            "name": "$properties.name",
            "value": {
                $convert: {
                    "input": "$properties.value",
                    "to": "decimal",
                    "onError": "$properties.value"
                }
            },
            "entityId": 1,
            "_id": 0
        }
    },
                {
                        $sort: {"value": -1}
                }
])