* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
1.4 KiB
1.4 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7fb7367417b2b2512c0d | 使用 model.findById() 方法,根据 _id 来搜索数据 | 2 | 301544 | use-model-findbyid-to-search-your-database-by-id |
--description--
在保存 document 的时候,MongoDB 会自动为它添加 _id
字段,并给该字段设置一个唯一的仅包含数字和字母的值。通过 _id
搜索是一个十分常见的操作,为此,Mongoose 提供了一个专门的方法。
--instructions--
执行Model.findById() -> Person
,使用 personId
作为搜索参数,根据 _id
找到对应的(唯一的)person。
--hints--
应成功地根据 Id 找到对应的数据
(getUserInput) =>
$.get(getUserInput('url') + '/_api/find-by-id').then(
(data) => {
assert.equal(data.name, 'test', 'item.name is not what expected');
assert.equal(data.age, 0, 'item.age is not what expected');
assert.deepEqual(
data.favoriteFoods,
['none'],
'item.favoriteFoods is not what expected'
);
assert.equal(data.__v, 0, 'The item should be not previously edited');
},
(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.
*/