| 
									
										
										
										
											2019-05-06 07:31:26 -04:00
										 |  |  |  | --- | 
					
						
							|  |  |  |  | id: 587d7fb6367417b2b2512c06 | 
					
						
							|  |  |  |  | title: Install and Set Up Mongoose | 
					
						
							| 
									
										
										
										
											2020-08-16 04:43:26 +05:30
										 |  |  |  | localeTitle: 安装和设置Mongoose | 
					
						
							| 
									
										
										
										
											2019-05-06 07:31:26 -04:00
										 |  |  |  | challengeType: 2 | 
					
						
							|  |  |  |  | --- | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ## Description
 | 
					
						
							| 
									
										
										
										
											2020-08-16 04:43:26 +05:30
										 |  |  |  | <section id='description'> <code>0</code>将mongodb和mongoose添加到项目的package.json中。然后需要猫鼬。将mLab数据库URI作为MONGO_URI存储在私有.env文件中。使用mongoose.connect连接到数据库( <Your URI> )  | 
					
						
							| 
									
										
										
										
											2019-05-06 07:31:26 -04:00
										 |  |  |  | </section> | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ## Instructions
 | 
					
						
							| 
									
										
										
										
											2020-08-16 04:43:26 +05:30
										 |  |  |  | <section id='instructions'>  | 
					
						
							| 
									
										
										
										
											2019-05-06 07:31:26 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | </section> | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ## Tests
 | 
					
						
							|  |  |  |  | <section id='tests'> | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ```yml | 
					
						
							|  |  |  |  | tests: | 
					
						
							| 
									
										
										
										
											2020-08-16 04:43:26 +05:30
										 |  |  |  |   - text: '"mongodb"依赖应该在package.json' | 
					
						
							| 
									
										
										
										
											2019-05-06 07:31:26 -04:00
										 |  |  |  |     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); })' | 
					
						
							| 
									
										
										
										
											2020-08-16 04:43:26 +05:30
										 |  |  |  |   - text: '"mongoose"依赖应该在package.json' | 
					
						
							| 
									
										
										
										
											2019-05-06 07:31:26 -04:00
										 |  |  |  |     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); })' | 
					
						
							| 
									
										
										
										
											2020-08-16 04:43:26 +05:30
										 |  |  |  |   - text: '"mongoose"应该连接到数据库' | 
					
						
							| 
									
										
										
										
											2019-05-06 07:31:26 -04:00
										 |  |  |  |     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); })' | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ``` | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | </section> | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ## Challenge Seed
 | 
					
						
							|  |  |  |  | <section id='challengeSeed'> | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | </section> | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ## Solution
 | 
					
						
							|  |  |  |  | <section id='solution'> | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ```js | 
					
						
							| 
									
										
										
										
											2020-08-16 04:43:26 +05:30
										 |  |  |  | // solution required | 
					
						
							| 
									
										
										
										
											2019-05-06 07:31:26 -04:00
										 |  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2020-08-13 17:24:35 +02:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | /section> |