将投影设置为数组的字段不起作用。 ApostropheCMS

问题描述 投票:0回答:1

我正在尝试设置一个投影以便从查询中检索较少的数据,但是当我尝试将一个array字段放入投影内部时,就会出现问题。这是我的片断模式

module.exports = {
  name: "attendee",
  extend: "apostrophe-pieces",
  alias: "attendees",
  label: "Attendee",
  pluralLabel: "Attendees",
  addFields: [
    {
      name: "_congress",
      label: "Congress this attendee has sign up for",
      type: "joinByOne",
      withType: "congress",
      filters: {
        projection: {
          _id: 1,
          title: 1
        }
      }
    },
    {
      name: "registrationDate",
      label: "Registration Date",
      type: "date"
    },
    {
      name: "registrationTime",
      label: "Registration Time",
      def: null,
      type: "time"
    },
    {
      name: "fields",
      label: "Fields",
      type: "array",
      titleField: "Array Label",
      schema: [
        {
          name: "name",
          type: "string",
          label: "String"
        },
        {
          name: "value",
          type: "string",
          label: "Value"
        }
      ]
    }
  ],

我的查询是这样的:

 return self.find(req, { congressId }).projection({ registrationDate: 1, registrationTime: 1, fields: 1 }).toArray();

[放上fields: 1时出现此异常enter image description here

否则将按预期返回数组:

enter image description here

我还在mongo shell中尝试了此查询,它的工作原理是:> db.aposDocs.find({_id: "ck35z61p400047e9e5ktt6wu4"}).projection( {fields: 1})

{ "_id" : "ck35z61p400047e9e5ktt6wu4", "fields" : [ { "id" : "attende1Field1", "name" : "name", "value" : "Name1" }, { "id" : "attendee1Field1", "name" : "lastName", "value" : "Last Name1" }, { "id" : "attendee1Field1", "name" : "treatment", "value" : "Treatment1" }, { "id" : "attendee1Field1", "name" : "email", "value" : "[email protected]" } ] } 也许我缺少什么?在此先感谢

apostrophe-cms
1个回答
0
投票

这似乎是由MongoDB错误引起的,至少在MongoDB nodejs驱动程序的2.x版本中。特别是字段名称fields不起作用,并产生您看到的错误:

© www.soinside.com 2019 - 2024. All rights reserved.