You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-1
Original file line number
Diff line number
Diff line change
@@ -280,11 +280,48 @@ Sometimes, when deploying a native module to production, oftentimes it is not po
280
280
281
281
## Application-specific tips and tricks
282
282
> :triangular_flag_on_post:**TODO**
283
-
* Setting up MongoDB.
284
283
* Setting up SQL.
285
284
* .NET in-process using Edge.js.
286
285
*[node-windows](https://github.com/coreybutler/node-windows): Windows services, logging, and commands using Node.js.
287
286
287
+
### Setting up and working with MongoDB
288
+
289
+
1.[Install MongoDB on Windows](https://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/)
290
+
2. Install the MongoDB npm package in the project root by running `npm install mongodb`
291
+
3.*(Optional, but helpful for IntelliSense support in Visual Studio Code)* Install the type definition file for MongoDB with `tsd install mongodb`
292
+
4. Load the mongodb module: `var MongoClient = require('mongodb').MongoClient;`
293
+
5.[Determine your MongoDB connection string URI](https://docs.mongodb.org/manual/reference/connection-string/) and set it to a variable: `var mongoUrl = '...'`;
> :bulb: MongoDB by default listens on 27017, but to verify this open the MongoDB log file `mongod.log` in the log directory and navigate the line that shows the port number (i.e. `[initandlisten] waiting for connections on port 27017`)
297
+
6. Access your MongoDB database by calling `MongoClient.connect()` and query the returned database
298
+
```javascript
299
+
MongoClient.connect(mongoUrl, function (err, db) {
300
+
if (!err) {
301
+
// query the collection and return a cursor to use
302
+
// to access the data
303
+
//
304
+
// note: calling find() with no parameters is the equivalent
305
+
// of pulling all documents in the collection with no
306
+
// predicate
307
+
var cursor =db.collection('yourCollectionName').find();
308
+
309
+
// loop through all of the documents returned by the
310
+
// query
311
+
cursor.each(function (err, element) {
312
+
if (!err && element) {
313
+
// do something with the document
314
+
}
315
+
// if error and the document are undefined then
316
+
// we have reached the no-more-documents condition
317
+
if (!err &&!element) {
318
+
console.log('done!');
319
+
}
320
+
});
321
+
}
322
+
});
323
+
```
324
+
288
325
## Node.js + Microsoft products, services, and contributions
289
326
*[**Visual Studio Code**](https://code.visualstudio.com/): Lightweight cross-platform editor for building and debugging modern web and cloud applications.
290
327
*[**Node.js Tools for Visual Studio**](https://www.visualstudio.com/features/node-js-vs): Free, open-source extension that turns Visual Studio into a powerful Node.js development environment.
0 commit comments