Files
freeCodeCamp/curriculum/challenges/russian/05-apis-and-microservices/mongodb-and-mongoose/delete-many-documents-with-model.remove.russian.md

32 lines
2.2 KiB
Markdown
Raw Normal View History

2019-02-11 16:57:05 -05:00
---
id: 587d7fb8367417b2b2512c11
title: Delete Many Documents with model.remove()
challengeType: 2
forumTopicId: 301538
localeTitle: Удалить много документов с model.remove ()
2019-02-11 16:57:05 -05:00
---
## Description
<section id='description'>
2019-02-11 16:57:05 -05:00
Model.remove () полезна для удаления всех документов, соответствующих заданным критериям. Удалите всех людей с именем «Мэри», используя Model.remove (). Передайте его в документ запроса с установленным полем «имя» и, конечно, с обратным вызовом.
Примечание: Model.remove () возвращает не удаленный документ, а объект JSON, содержащий результат операции и количество затронутых элементов. Не забудьте передать его обратному вызову done (), так как мы используем его в тестах.
2019-02-11 16:57:05 -05:00
</section>
## Instructions
<section id='instructions'>
Delete all the people whose name is “Mary”, using <code>Model.remove()</code>. Pass it to a query document with the <code>name</code> field set, and of course a callback.
<strong>Note:</strong> The <code>Model.remove()</code> doesnt return the deleted document, but a JSON object containing the outcome of the operation, and the number of items affected. Dont forget to pass it to the <code>done()</code> callback, since we use it in tests.
2019-02-11 16:57:05 -05:00
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: Deleting many items at once should succeed
2019-02-11 16:57:05 -05:00
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); })'
```
</section>