zoukankan      html  css  js  c++  java
  • mongo views

    db.itemsView.drop();

    db.items.aggregate([
    {
    "$match": {
    "status": "true"
    }
    },
    {
    "$unwind": {
    "path": "$globalOptions",
    "preserveNullAndEmptyArrays": true
    }
    },
    {
    "$lookup": {
    "from": "globaloptiongroups",
    "localField": "globalOptions",
    "foreignField": "_id",
    "as": "globaloptiongroups"
    }
    },
    {
    "$unwind": {
    "path": "$globaloptiongroups",
    "preserveNullAndEmptyArrays": true
    }
    },
    {
    "$group": {
    "_id": "$_id",
    "globaloptiongroups": {
    "$push": "$globaloptiongroups"
    },
    "name": {
    "$first": "$name"
    },
    "merchantId": {
    "$first": "$merchantId"
    },
    "customerOptions": {
    "$first": "$customerOptions"
    },
    "properties": {
    "$first": "$properties"
    },
    "price": {
    "$first": "$price"
    },
    "picture": {
    "$first": "$picture"
    },
    "description": {
    "$first": "$description"
    },
    "category": {
    "$first": "$category"
    },
    "order": {
    "$first": "$order"
    }
    }
    },
    {
    "$project": {
    "_id": 1,
    "name": 1,
    "merchantId": 1,
    "options": 1,
    "price": 1,
    "picture": 1,
    "description": 1,
    "category": 1,
    "order": 1,
    "groupOptions": {
    "$setUnion": [
    "$groupOptions",
    "$customerOptions"
    ]
    }
    }
    },
    {
    "$sort": {
    "order": 1
    }
    }
    ]).saveAsView("itemsView");

  • 相关阅读:
    C#:字符串(转载9)
    C# 数组(转载8)
    C#:可空类型(转载7)
    XD 05
    eclipse 快捷键 干货
    XD 04
    XD 03
    model, mapper, xml
    02 MyBatis & Druid
    注解 用到
  • 原文地址:https://www.cnblogs.com/jayruan/p/7154212.html
Copyright © 2011-2022 走看看