Mongodb 这个json示例的mongoose模式是什么?

Mongodb 这个json示例的mongoose模式是什么?,mongodb,mongoose,Mongodb,Mongoose,我正在使用MongoDb数据库进行Node.js项目。 我需要这个json示例的模式: 我正在使用MongoDb数据库进行Node.js项目。 我需要这个json示例的模式 MongoDb文件: { "container_number": "ddd", "container_Date": "2/2/2018", "scannedProductArray": { "CCR": [ { "ScannedDate": { "$date

我正在使用MongoDb数据库进行Node.js项目。 我需要这个json示例的模式:

我正在使用MongoDb数据库进行Node.js项目。 我需要这个json示例的模式

MongoDb文件:

{
  "container_number": "ddd",
  "container_Date": "2/2/2018",
  "scannedProductArray": {
    "CCR": [
      {
        "ScannedDate": {
          "$date": "2018-03-28T20:54:57.663Z"
        },
        "productNumber": "4656874974",
        "productType": "CCR"
      },
      {
        "ScannedDate": {
          "$date": "2018-03-28T20:55:23.698Z"
        },
        "productNumber": "4656874974",
        "productType": "CCR"
      }
    ],
    "CCH": [
      {
        "ScannedDate": {
          "$date": "2018-03-28T21:25:16.202Z"
        },
        "productNumber": "4656874974",
        "productType": "CCR"
      },
      {
        "ScannedDate": {
          "$date": "2018-03-28T21:26:08.696Z"
        },
        "productNumber": "4656874974",
        "productType": "CCR"
      }
    ]
  }
}

这可能对您有所帮助。

我想这样定义模式:

const Product = {
    ScannedDate: {
        type: Object,
    },
    productNumber: {
        type: String,
    },
    productType: {
        type: String,
        default: 'CCR',
    }
};
const Item = {
    itemName: {
        type: [Product],
    },
};
const Container = {
    container_number: {
        type: String,
    },
    container_Date: {
        type: String
    },
    scannedProductArray: {
        type: Object, // Item
    }
};

如果
CCR
/
CCH
字段是动态的,我可以使用
type:Object
而不是特定的结构。我自己而不是mongoose验证这些数组项。

我需要scannedProductArray是动态的,例如CCR和CCH,我需要向对象ScannedProductArrayES scannedProductArray添加动态元素,其中的元素也是动态的(CCH、CCR、mmc.hhj等)元素。scannedProductArray中的每个元素都是预定义模式的数组,但scannedProductArray模式的问题尚未定义
const Product = {
    ScannedDate: {
        type: Object,
    },
    productNumber: {
        type: String,
    },
    productType: {
        type: String,
        default: 'CCR',
    }
};
const Item = {
    itemName: {
        type: [Product],
    },
};
const Container = {
    container_number: {
        type: String,
    },
    container_Date: {
        type: String
    },
    scannedProductArray: {
        type: Object, // Item
    }
};