Files
freeCodeCamp/curriculum/challenges/chinese/05-apis-and-microservices/mongodb-and-mongoose/delete-many-documents-with-model.remove.chinese.md
Beau Carnes 6b1992ee7c fix: Add Api challenges - Chinese translation (#35164)
* fix: Add Api challenges - Chinese translation

* fix: md formatting

* fix: md formatting
2019-05-06 06:31:26 -05:00

1.5 KiB
Raw Blame History

id, title, localeTitle, challengeType
id title localeTitle challengeType
587d7fb8367417b2b2512c11 Delete Many Documents with model.remove() 使用model.remove删除许多文档 2

Description

Model.remove用于删除与给定条件匹配的所有文档。使用Model.remove删除名称为“Mary”的所有人员。将其传递给查询文档其中设置了“name”字段当然还有回调。 0注意Model.remove不返回已删除的文档而是返回包含操作结果和受影响项目数的JSON对象。不要忘记将它传递给done回调因为我们在测试中使用它。

Instructions

Tests

tests:
  - text: 一次删除多个项目应该会成功
    testString: 'getUserInput => $.ajax({url: getUserInput(''url'') + ''/_api/remove-many-people'', type: ''POST'', contentType:''application/json'', data: JSON.stringify([{name: ''Mary'', age: 16, favoriteFoods: [''lollipop'']}, {name: ''Mary'', age: 21, favoriteFoods: [''steak'']}])}).then(data => { assert.isTrue(!!data.ok, ''The mongo stats are not what expected''); assert.equal(data.n, 2, ''The number of items affected is not what expected''); assert.equal(data.count, 0, ''the db items count is not what expected''); }, xhr => { throw new Error(xhr.responseText); })'

Challenge Seed

Solution

// solution required