1.7 KiB
1.7 KiB
id, title, challengeType, isHidden, localeTitle
id | title | challengeType | isHidden | localeTitle |
---|---|---|---|---|
587d7fb6367417b2b2512c09 | Create and Save a Record of a Model | 2 | false | 用模型来创建并保存一条记录 |
Description
Instructions
name
、age
和favoriteFoods
字段。这些字段的类型必须符合 Person Schema 里面定义的类型。然后调用document.save()
。使用 Node 惯例传递 callback。通常情况下,所有的 CRUD(增查改删)方法都会像下面一样作为最后一个参数去执行一个callback()
。
/* Example */
// ...
person.save(function(err, data) {
// ...do your stuff here...
});
Tests
tests:
- text: 成功创建一条 db 并保存。
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
/**
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.
*/