freeCodeCamp/curriculum/challenges/chinese/05-apis-and-microservices/mongodb-and-mongoose/use-model.find-to-search-yo...

1.3 KiB
Raw Blame History

id title localeTitle challengeType
587d7fb7367417b2b2512c0b Use model.find() to Search Your Database 使用model.find搜索数据库 2

Description

0使用Model.find - > [Person]查找具有给定名称的所有人0在最简单的用法中Model.find接受查询文档JSON对象作为第一个参数然后接受回调。它返回一个匹配数组。它支持极其广泛的搜索选项。在文档中查看它。使用函数参数personName作为搜索关键字。

Instructions

Tests

tests:
  - text: 找到与标准对应的所有项目都应该成功
    testString: 'getUserInput => $.post(getUserInput(''url'') + ''/_api/find-all-by-name'', {name: ''r@nd0mN4m3'', age: 24, favoriteFoods: [''pizza'']}).then(data => { assert.isArray(data, ''the response should be an Array'');  assert.equal(data[0].name, ''r@nd0mN4m3'', ''item.name is not what expected''); assert.equal(data[0].__v, 0, ''The item should be not previously edited''); }, xhr => { throw new Error(xhr.responseText); })'

Challenge Seed

Solution

// solution required