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
+20-15Lines changed: 20 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Mongoose
2
2
3
-
Mongoose is a [MongoDB](https://www.mongodb.org/) object modeling tool designed to work in an asynchronous environment.
3
+
Mongoose is a [MongoDB](https://www.mongodb.org/) object modeling tool designed to work in an asynchronous environment. It has both a callbacks and Promise-style API.
Check out the [plugins search site](http://plugins.mongoosejs.io/) to see hundreds of related modules from the community. Next, learn how to write your own plugin from the [docs](http://mongoosejs.com/docs/plugins.html) or [this blog post](http://thecodebarbarian.com/2015/03/06/guide-to-mongoose-plugins).
@@ -55,6 +45,16 @@ First install [node.js](http://nodejs.org/) and [mongodb](https://www.mongodb.or
55
45
$ npm install mongoose
56
46
```
57
47
48
+
## Importing
49
+
50
+
```javascript
51
+
// Using Node.js `require()`
52
+
constmongoose=require('mongoose');
53
+
54
+
// Using ES6 imports
55
+
importmongoosefrom'mongoose';
56
+
```
57
+
58
58
## Overview
59
59
60
60
### Connecting to MongoDB
@@ -64,9 +64,7 @@ First, we need to define a connection. If your app uses only one database, you s
64
64
Both `connect` and `createConnection` take a `mongodb://` URI, or the parameters `host, database, port, options`.
@@ -172,7 +170,14 @@ MyModel.find({}, function (err, docs) {
172
170
});
173
171
```
174
172
175
-
You can also `findOne`, `findById`, `update`, etc. For more details check out [the docs](http://mongoosejs.com/docs/queries.html).
173
+
You can also `findOne`, `findById`, `update`, etc.
174
+
175
+
```js
176
+
constinstance=awaitMyModel.findOne({ ... });
177
+
console.log(instance.my.key); // 'hello'
178
+
```
179
+
180
+
For more details check out [the docs](http://mongoosejs.com/docs/queries.html).
176
181
177
182
**Important!** If you opened a separate connection using `mongoose.createConnection()` but attempt to access the model through `mongoose.model('ModelName')` it will not work as expected since it is not hooked up to an active db connection. In this case access your model through the connection you created:
0 commit comments