Files
freeCodeCamp/curriculum/challenges/chinese/05-apis-and-microservices/mongodb-and-mongoose/perform-new-updates-on-a-document-using-model.findoneandupdate.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.7 KiB
Raw Blame History

id, title, localeTitle, challengeType
id title localeTitle challengeType
587d7fb8367417b2b2512c0f Perform New Updates on a Document Using model.findOneAndUpdate() 使用model.findOneAndUpdate对文档执行新更新 2

Description

0最新版本的mongoose具有简化文档更新的方法。一些更高级的功能即前/后挂钩验证与此方法的行为不同因此Classic方法在许多情况下仍然有用。在按Id搜索时可以使用findByIdAndUpdate0按名称查找人员并将其年龄设置为20.使用函数参数personName作为搜索关键字。 0提示:我们希望您返回更新的文档。为此,您需要将选项文档{newtrue}作为findOneAndUpdate的第三个参数传递。默认情况下这些方法返回未修改的对象。

Instructions

Tests

tests:
  - text: findOneAndUpdate项应该成功
    testString: 'getUserInput => $.post(getUserInput(''url'') + ''/_api/find-one-update'', {name:''Dorian Gray'', age: 35, favoriteFoods:[''unknown'']}).then(data => { assert.equal(data.name, ''Dorian Gray'', ''item.name is not what expected''); assert.equal(data.age, 20, ''item.age is not what expected''); assert.deepEqual(data.favoriteFoods, [''unknown''], ''item.favoriteFoods is not what expected''); assert.equal(data.__v, 0, ''findOneAndUpdate does not increment version by design !!!''); }, xhr => { throw new Error(xhr.responseText); })'

Challenge Seed

Solution

// solution required