freeCodeCamp/curriculum/challenges/japanese/05-back-end-development-and.../mongodb-and-mongoose/delete-one-document-using-m...

1.6 KiB

id title challengeType forumTopicId dashedName
587d7fb8367417b2b2512c10 Model.findByIdAndRemove を使用して 1 つのドキュメントを削除する 2 301539 delete-one-document-using-model-findbyidandremove

--description--

findByIdAndRemovefindOneAndRemove も、前回の更新メソッドと同様です。 これらは、削除したドキュメントを db に渡します。 いつものように、関数引数 personId を検索キーとして使用してください。

--instructions--

removeById 関数を変更して、1 人の個人を _id で削除してください。 findByIdAndRemove() または findOneAndRemove() メソッドのいずれかを使用する必要があります。

--hints--

アイテムを正しく削除する必要があります。

(getUserInput) =>
  $.post(getUserInput('url') + '/_api/remove-one-person', {
    name: 'Jason Bourne',
    age: 36,
    favoriteFoods: ['apples']
  }).then(
    (data) => {
      assert.equal(data.name, 'Jason Bourne', 'item.name is not what expected');
      assert.equal(data.age, 36, 'item.age is not what expected');
      assert.deepEqual(
        data.favoriteFoods,
        ['apples'],
        'item.favoriteFoods is not what expected'
      );
      assert.equal(data.__v, 0);
      assert.equal(data.count, 0, 'the db items count is not what expected');
    },
    (xhr) => {
      throw new Error(xhr.responseText);
    }
  );

--solutions--

/**
  Backend challenges don't need solutions, 
  because they would need to be tested against a full working project. 
  Please check our contributing guidelines to learn more.
*/