Files
freeCodeCamp/curriculum/challenges/portuguese/05-apis-and-microservices/mongodb-and-mongoose/use-model.findbyid-to-search-your-database-by-id.portuguese.md
Beau Carnes b85e849482 fix: Add Api challenges - Portuguese translation (#35165)
* fix: Add Api challenges - Portuguese translation

* fix: md formatting
2019-05-06 06:31:59 -05:00

1.4 KiB

id, title, localeTitle, challengeType
id title localeTitle challengeType
587d7fb7367417b2b2512c0d Use model.findById() to Search Your Database By _id Use model.findById () para pesquisar seu banco de dados por _id 2

Description

Ao salvar um documento, o mongodb adiciona automaticamente o campo _id e o configura para uma chave alfanumérica exclusiva. Pesquisar por _id é uma operação extremamente frequente, então o mangusto fornece um método dedicado para isso. Encontre a pessoa (somente !!) tendo um determinado _id, usando Model.findById () -> Person. Use o argumento da função personId como chave de busca.

Instructions

Tests

tests:
  - text: Encontrar um item por Id deve ter sucesso
    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