search and replace ```\n< with ```\n\n< to ensure there's an empty line before closing tags
1.3 KiB
1.3 KiB
id, title, localeTitle, challengeType
| id | title | localeTitle | challengeType |
|---|---|---|---|
| 587d7fb7367417b2b2512c0d | Use model.findById() to Search Your Database By _id | 使用model.findById()按_id搜索数据库 | 2 |
Description
0保存文档时,mongodb会自动添加字段_id,并将其设置为唯一的字母数字键。按_id搜索是一种非常频繁的操作,因此mongoose为它提供了一种专用方法。使用Model.findById() - > Person找到具有给定_id的(仅!!)人物。使用函数参数personId作为搜索关键字。
Instructions
Tests
tests:
- text: 找到Id应该成功的项目
testString: "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); })"
Challenge Seed
Solution
// solution required
/section>