具有混合类型的Mongoose模式表现得很尴尬

时间:2014-07-23 13:38:36

标签: javascript node.js mongodb express mongoose

我有一个像这样声明的Event模式:

var EventSchema = new Schema({
  type: String,
  action: String,
  createdAt: { type : Date, default : Date.now },
  payload: {},
});

我尝试使用此哈希创建一个新实例(为清晰起见省略了其他属性):

{
  "payload": {
    "apikey": {
      "created_at": "2014-07-22T18:35:19.995Z",
      "id": 1,
      "owner_id": 3,
      "owner_type": "User",
      "permissions": [
        {
          "can_create": false,
          "can_delete": false,
          "can_read": false,
          "can_update": false,
          "created_at": "2014-07-22T18:37:18.111Z",
          "id": 3,
          "key": "second",
          "role_id": 1,
          "updated_at": "2014-07-22T18:37:18.121Z"
        },
        {
          "can_create": false,
          "can_delete": false,
          "can_read": false,
          "can_update": false,
          "created_at": "2014-07-22T18:37:18.111Z",
          "id": 2,
          "key": "permission-key-2",
          "role_id": 1,
          "updated_at": "2014-07-22T18:37:18.121Z"
        }
      ],
      "realm_id": 6,
      "realm_type": "Organization",
      "secret": "c35ca06eab38850493bae0f974787587",
      "token": "a9e4691ebc1551b6b1ee2147397248a6",
      "updated_at": "2014-07-22T18:40:26.553Z"
    }
  }
}

但是不是保存我发送的结构,而是像这样保存它:

{
    "apikey": {
        "created_at": "2014-07-22 18:35:19 UTC",
        "id": "1",
        "owner_id": "3",
        "owner_type": "User",
        "permissions": {
            "can_create": [
                "false",
                "false"
            ],
            "can_delete": [
                "false",
                "false"
            ],
            "can_read": [
                "false",
                "false"
            ],
            "can_update": [
                "false",
                "false"
            ],
            "created_at": [
                "2014-07-22 18:37:18 UTC",
                "2014-07-22 18:37:18 UTC"
            ],
            "id": [
                "3",
                "2"
            ],
            "key": [
                "second",
                "permission-key-2"
            ],
            "role_id": [
                "1",
                "1"
            ],
            "updated_at": [
                "2014-07-22 18:37:18 UTC",
                "2014-07-22 18:37:18 UTC"
            ]
        },
        "realm_id": "6",
        "realm_type": "Organization",
        "secret": "c35ca06eab38850493bae0f974787587",
        "token": "a9e4691ebc1551b6b1ee2147397248a6",
        "updated_at": "2014-07-22 18:40:26 UTC"
    }
}

你知道为什么吗?

0 个答案:

没有答案