如何在新的“父实体”中添加“现有实体”?

时间:2020-10-28 14:01:51

标签: mongodb nestjs typeorm

我有一个现有的“子实体”,当我创建一个新的“父实体”时,我想将现有的子实体与新的子实体相关联。

  async createParent(fieldOne: string, fieldTwo: string, existentChild) {
  
    const newParent = await this.defaultRepository.create({
      fieldOne,
      fieldTwo
    });
    newParent.children = [existentChild];

    return this.defaultRepository.save(newParent);
  }

我收到此错误

MongoError: '$set' is empty. You must specify a field like so: {$set: {<field>: ...}}

0 个答案:

没有答案