Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 如何从关系';存储在数组中的数据';身份证号码_Mongodb_Foreign Keys_Relationship_Loopback - Fatal编程技术网

Mongodb 如何从关系';存储在数组中的数据';身份证号码

Mongodb 如何从关系';存储在数组中的数据';身份证号码,mongodb,foreign-keys,relationship,loopback,Mongodb,Foreign Keys,Relationship,Loopback,我有一个模型,它的数据如下 "id": { "type": "string", "id": true, "defaultFn": "uuidv4" }, "batchType": { "type": "string", "required": true, "default": "COURSE" }, "venue": { "type": "string", "requi

我有一个模型,它的数据如下

"id": {
      "type": "string",
      "id": true,
      "defaultFn": "uuidv4"
    },
    "batchType": {
      "type": "string",
      "required": true,
      "default": "COURSE"
    },
    "venue": {
      "type": "string",
      "required": true
    },
还有一个模特说预订了浴室

"batchesId": {
     "type": [
       "string"
     ],
     "required": true
   },
并创建了从批次模型到BookedBatchs模型的关系,如下所示:

 "relations": {
    "bookedBatches": {
      "type": "referencesMany",
      "model": "bookedBatches",
      "foreignKey": "batchesId",
      "primaryKey": "id"
    }
  }

现在,我希望所有具有预订详细信息的批次都存储为批次模型预订详细信息中Id的数组


let reqObject = {
                    "where": {
                        "and": [{
                            userId: userId,
                            isActive: true
                        }]
                    },
                    "order": "createdAt DESC",
                    include: [
                        {{
                            relation:"bookedBatches"}}]
}


Batches.find(reqObject, (resError, resData) => {
                    if (resError) {
                        return cb(new HttpErrors.BadRequest(resError, {
                            expose: false
                        }))
                    }
                    return cb(null, resData);
                })
但是我没有得到任何价值,任何人都可以通过关系来帮助获得价值吗


谢谢大家!

我已经改进了你的代码。请试试这个

 let reqObject = {
  "where": {
    "and": [{
      userId: userId,
      isActive: true
    }]
  },
  "order": "createdAt DESC",
  include: [
    {
      relation: "bookedBatches",
      scope: { fields: ["id","batchesId"] }
    }
  ]
}


Batches.find(reqObject, (resError, resData) => {
  if (resError) {
    return cb(new HttpErrors.BadRequest(resError, {
      expose: false
    }))
  }
  return cb(null, resData);
})