$ push создает новый объект только с _id, без свойств - feathsjs + mongoose - PullRequest
0 голосов
/ 20 июня 2019

Я пытаюсь вставить объект (с одним свойством text) в массив поддокумента, используя $ push:

await this.app.service("someService").patch(
      null,
      {
        $push: { "subDocuments.$.textArray": { text: "stuff" }}
      },
      {
        query: {
          _id: parentId,
          "subDocuments._id": subDocumentId
        }
      }
    );
  }

Модель выглядит так:

const ParentSchema = new Schema({
    subDocuments: [SubDocumentSchema]
});

const SubDocumentSchema = new Schema({ 
     textArray: [
          {
              text: { type: String }
          }
     ]
});

Объект создан, но это пустой объект с _id в качестве единственного свойства. Чего мне не хватает?

1 Ответ

0 голосов
/ 20 июня 2019

Пожалуйста, объявите схему как:

const ParentSchema = new Schema({
    subDocuments: [SubDocumentSchema]
});

const SubDocumentSchema = new Schema({ 
     textArray: [
          {
              text: { type: String }
          }
     ]
}, { _id: false });
...