-
Notifications
You must be signed in to change notification settings - Fork 31
Translate mongodb-and-mongoose #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jiangyuzhen
wants to merge
4
commits into
FreeCodeCampChina:translate
Choose a base branch
from
jiangyuzhen:translate
base: translate
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,19 +8,19 @@ | |
| "id": "587d7fb6367417b2b2512c06", | ||
| "title": "Install and Set Up Mongoose", | ||
| "description": [ | ||
| "Add mongodb and mongoose to the project’s package.json. Then require mongoose. Store your mLab database URI in the private .env file as MONGO_URI. Connect to the database using mongoose.connect(<Your URI>)" | ||
| "在 package.json 文件中添加 MongoDB 和 Mongoose 依赖, 将 mLab 数据库的 URI 作为 MONGO_URI 变量存储在私有 .env 文件中。然后 <code>require('mongoose')</code>,使用 <code>mongoose.connect(<Your URI>)</code> 命令来连接数据库。" | ||
| ], | ||
| "tests": [ | ||
| { | ||
| "text": "\"mongodb\" dependency should be in package.json", | ||
| "text": "在 package.json 文件中应该有 \"mongodb\" 依赖", | ||
| "testString": "getUserInput => $.get(getUserInput('url') + '/_api/file/package.json').then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, 'mongodb'); }, xhr => { throw new Error(xhr.responseText); })" | ||
| }, | ||
| { | ||
| "text": "\"mongoose\" dependency should be in package.json", | ||
| "text": "在 package.json 文件中应该有 \"mongoose\" 依赖", | ||
| "testString": "getUserInput => $.get(getUserInput('url') + '/_api/file/package.json').then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, 'mongoose'); }, xhr => { throw new Error(xhr.responseText); })" | ||
| }, | ||
| { | ||
| "text": "\"mongoose\" should be connected to a database", | ||
| "text": "\"mongoose\" 应该已经连接数据库", | ||
| "testString": "getUserInput => $.get(getUserInput('url') + '/_api/is-mongoose-ok').then(data => {assert.isTrue(data.isMongooseOk, 'mongoose is not connected')}, xhr => { throw new Error(xhr.responseText); })" | ||
| } | ||
| ], | ||
|
|
@@ -33,9 +33,10 @@ | |
| "title": "Create a Model", | ||
| "description": [ | ||
| "First of all we need a Schema. Each schema maps to a MongoDB collection. It defines the shape of the documents within that collection.", | ||
| "Schemas are building block for Models. They can be nested to create complex models, but in this case we’ll keep things simple.", | ||
| "A model allows you to create instances of your objects, called documents.", | ||
| "Create a person having this prototype :", | ||
| "首先,我们需要一个 Schema,每一个 Schema 对应一个 MongoDB collection, 并且在那个 collection 里面定义 documents 的模型。", | ||
| "Schemas 是 Models 的构建块。它们可以嵌套来创建复杂的模型,但是这里,我们只学习简单的用法。", | ||
| "Model 可以被实例化,实例化后的对象称为 documents", | ||
| "创建一个拥有以下 Prototype 的 Person 对象:", | ||
| "<code>- Person Prototype -</code>", | ||
| "<code>--------------------</code>", | ||
| "<code>name : string [required]</code>", | ||
|
|
@@ -44,9 +45,10 @@ | |
| "Use the mongoose basic schema types. If you want you can also add", | ||
| "more fields, use simple validators like required or unique,", | ||
| "and set default values. See the <a href='http://mongoosejs.com/docs/guide.html'>mongoose docs</a>.", | ||
| "你可以使用 基础的 SchemaTypes 去添加更多的字段,比如使用 required 或者 unique 这样的简单验证去设置默认值. 参考 <a href='http://mongoosejs.com/docs/guide.html'>Mongoose 文档</a>.", | ||
| "[C]RUD Part I - CREATE", | ||
| "Note: Glitch is a real server, and in real servers the interactions with the db happen in handler functions. These function are executed when some event happens (e.g. someone hits an endpoint on your API). We’ll follow the same approach in these exercises. The done() function is a callback that tells us that we can proceed after completing an asynchronous operation such as inserting, searching, updating or deleting. It’s following the Node convention and should be called as done(null, data) on success, or done(err) on error.", | ||
| "Warning - When interacting with remote services, errors may occur !", | ||
| "注意: Glitch 是一个真实的服务, 并且通过 handler 函数和 db 进行交互。 这些函数通过一些事件去触发(例如:有人从终端调用了你的 API), 我们在这些练习中遵循同样的方法。 比如,我们在完成 nserting、 searching、 updating 或者 deleting 这样的异步操作后接着回调 <code>done()</code> 函数。 它遵循 Node 的惯例,需要在 success 时回调 <code>done(null, data)</code>, 在 error 时回调 <code>done(err)</code>。", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 多了好多空格 |
||
| "Warning - 当与远程服务器交互时可能发生错误!", | ||
| "<code>/* Example */</code>", | ||
| "<code>var someFunc = function(done) {</code>", | ||
| "<code> //... do something (risky) ...</code>", | ||
|
|
@@ -56,7 +58,7 @@ | |
| ], | ||
| "tests": [ | ||
| { | ||
| "text": "Creating an instance from a mongoose schema should succeed", | ||
| "text": "成功创建一个 Schema 实例", | ||
| "testString": "getUserInput => $.post(getUserInput('url') + '/_api/mongoose-model', {name: 'Mike', age: 28, favoriteFoods: ['pizza', 'cheese']}).then(data => { assert.equal(data.name, 'Mike', '\"model.name\" is not what expected'); assert.equal(data.age, '28', '\"model.age\" is not what expected'); assert.isArray(data.favoriteFoods, '\"model.favoriteFoods\" is not an Array'); assert.include(data.favoriteFoods, 'pizza', '\"model.favoriteFoods\" does not include the expected items'); assert.include(data.favoriteFoods, 'cheese', '\"model.favoriteFoods\" does not include the expected items'); }, xhr => { throw new Error(xhr.responseText); })" | ||
| } | ||
| ], | ||
|
|
@@ -68,7 +70,7 @@ | |
| "id": "587d7fb6367417b2b2512c09", | ||
| "title": "Create and Save a Record of a Model", | ||
| "description": [ | ||
| "Create a document instance using the Person constructor you build before. Pass to the constructor an object having the fields name, age, and favoriteFoods. Their types must be conformant to the ones in the Person Schema. Then call the method document.save() on the returned document instance. Pass to it a callback using the Node convention. This is a common pattern, all the following CRUD methods take a callback function like this as the last argument.", | ||
| "使用 Person 的 constructor(构造器) 函数可以创建一个 document 对象,该对象包含 <code>name</code>、 <code>age</code> 和 <code>favoriteFoods</code> 字段。 这些字段的类型必须符合 Person Schema 里面定义的类型。 然后调用 <code>document.save()</code>。 使用 Node 惯例传递 callback。通常情况下,所有的 CRUD(增查改删) 方法都会像下面一样作为最后一个参数去执行一个 <code>callback()</code>。", | ||
| "<code>/* Example */</code>", | ||
| "<code>// ...</code>", | ||
| "<code>person.save(function(err, data) {</code>", | ||
|
|
@@ -77,7 +79,7 @@ | |
| ], | ||
| "tests": [ | ||
| { | ||
| "text": "Creating and saving a db item should succeed", | ||
| "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); })" | ||
| } | ||
| ], | ||
|
|
@@ -89,7 +91,7 @@ | |
| "id": "587d7fb7367417b2b2512c0a", | ||
| "title": "Create Many Records with model.create()", | ||
| "description": [ | ||
| "Sometimes you need to create many instances of your models, e.g. when seeding a database with initial data. Model.create() takes an array of objects like [{name: 'John', ...}, {...}, ...] as the first argument, and saves them all in the db. Create many people with Model.create(), using the function argument arrayOfPeople." | ||
| "有时你需要创建很多的 model 实例。 例如:在使用初始数据为数据库初始化时, <code>Model.create()</code> 接受一组像 <code>[{name: 'John', ...}, {...}, ...]</code> 的数组作为第一个参数,并将其保存到数据库。使用 <code>arrayOfPeople</code> 作为 <code>Model.create()</code> 的参数创建很多个 people 实例。" | ||
| ], | ||
| "tests": [ | ||
| { | ||
|
|
@@ -105,12 +107,12 @@ | |
| "id": "587d7fb7367417b2b2512c0b", | ||
| "title": "Use model.find() to Search Your Database", | ||
| "description": [ | ||
| "Find all the people having a given name, using Model.find() -> [Person]", | ||
| "In its simplest usage, Model.find() accepts a query document (a JSON object ) as the first argument, then a callback. It returns an array of matches. It supports an extremely wide range of search options. Check it in the docs. Use the function argument personName as search key." | ||
| "使用 <code>Model.find() -> [Person]</code> 来查询给定名称的所有的人。", | ||
| "最简单的用法: <code>Model.find()</code> 接受一个查询的 document (一个 JSON 对象 ) 作为第一参数, 然后是回调。 它将返回匹配到的项目组成的数组。 这个支持极其广泛的搜索选项。 使用人名作为搜索的关键词, 来校验它。" | ||
| ], | ||
| "tests": [ | ||
| { | ||
| "text": "Find all items corresponding to a criteria should succeed", | ||
| "text": "成功找到所有符合条件的 item(项目)。", | ||
| "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); })" | ||
| } | ||
| ], | ||
|
|
@@ -122,11 +124,11 @@ | |
| "id": "587d7fb7367417b2b2512c0c", | ||
| "title": "Use model.findOne() to Return a Single Matching Document from Your Database", | ||
| "description": [ | ||
| "Model.findOne() behaves like .find(), but it returns only one document (not an array), even if there are items. It is especially useful when searching by properties that you have declared as unique. Find just one person which has a certain food in her favorites, using Model.findOne() -> Person. Use the function argument food as search key." | ||
| "<code>Model.findOne()</code> 表现像 <code>Model.find()</code>, 但是它仅仅返回一个 document (而不是一个数组), 即使数据库里有很多条 item(项目)。 当你按声明成 <code>unique</code> 的属性进行搜索时,<code>Model.findOne()</code> 尤其有用。 把食物作为 <code>Model.findOne() -> Person</code> 的参数,来找到一个在她的爱好中有某一食物的人。" | ||
| ], | ||
| "tests": [ | ||
| { | ||
| "text": "Find one item should succeed", | ||
| "text": "成功找到一个 item(项目)。", | ||
| "testString": "getUserInput => $.post(getUserInput('url') + '/_api/find-one-by-food', {name: 'Gary', age: 46, favoriteFoods: ['chicken salad']}).then(data => { assert.equal(data.name, 'Gary', 'item.name is not what expected'); assert.deepEqual(data.favoriteFoods, ['chicken salad'], 'item.favoriteFoods is not what expected'); assert.equal(data.__v, 0, 'The item should be not previously edited'); }, xhr => { throw new Error(xhr.responseText); })" | ||
| } | ||
| ], | ||
|
|
@@ -138,11 +140,11 @@ | |
| "id": "587d7fb7367417b2b2512c0d", | ||
| "title": "Use model.findById() to Search Your Database By _id", | ||
| "description": [ | ||
| "When saving a document, mongodb automatically adds the field _id, and set it to a unique alphanumeric key. Searching by _id is an extremely frequent operation, so moongose provides a dedicated method for it. Find the (only!!) person having a given _id, using Model.findById() -> Person. Use the function argument personId as search key." | ||
| "当我们保存一个 document, MongoDB 自动添加 _id 字段, 并给该字段设置 unique(唯一) 属性。通过 _id 搜索是一个非常频繁的操作,所以 Mongose 为它提供了一个专门的方法。使用人物 Id 作为参数,执行 <code>Model.findById() -> Person</code>, 找到这个_id 对应的唯一的一个人。" | ||
| ], | ||
| "tests": [ | ||
| { | ||
| "text": "Find an item by Id should succeed", | ||
| "text": "通过 Id 成功找到对应的 item(项目)。", | ||
| "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); })" | ||
| } | ||
| ], | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你可以使用 基础的 SchemaTypes这里多了空格。“使用”之后这句话里,句号要用全角的,你貌似忘了改了