Files
freeCodeCamp/curriculum/challenges/english/05-apis-and-microservices/mongodb-and-mongoose/create-and-save-a-record-of-a-model.english.md
Greg Smith 1779971cff Fix typos in MongoDB lessons and clarify some language (#35020)
* docs: typos and change some language for clarity

* fix: typo regression

* fix: added the word is
2019-02-27 13:41:19 -06:00

1.5 KiB

id, title, challengeType
id title challengeType
587d7fb6367417b2b2512c09 Create and Save a Record of a Model 2

Description

Create a document instance using the Person constructor you built before. Pass an object to the constructor with the fields name, age, and favoriteFoods. Their types must conform to the ones in the Person Schema. Then call the method document.save() on the returned document instance. Pass it a callback using the Node convention you saw before. This is a common pattern, all the following CRUD methods take a callback function like this as the last argument. /* Example */ // ... person.save(function(err, data) { // ...do your stuff here... });

Instructions

Tests

tests:
  - text: Creating and saving a db item should succeed
    testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/create-and-save-person'').then(data => { assert.isString(data.name, ''"item.name" should be a String''); assert.isNumber(data.age, ''28'', ''"item.age" should be a Number''); assert.isArray(data.favoriteFoods, ''"item.favoriteFoods" should be an Array''); assert.equal(data.__v, 0, ''The db item should be not previously edited''); }, xhr => { throw new Error(xhr.responseText); })'

Challenge Seed

Solution

// solution required