Skip to content

Commit

Permalink
Update connections.md
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 authored May 24, 2023
1 parent 45a2c29 commit 196c822
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions docs/connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mongoose to establish a connection to MongoDB.
mongoose.connect('mongodb://127.0.0.1:27017/myapp');
const MyModel = mongoose.model('Test', new Schema({ name: String }));
// Works
MyModel.findOne();
await MyModel.findOne();
```

That's because mongoose buffers model function calls internally. This
Expand All @@ -52,12 +52,14 @@ connecting.

```javascript
const MyModel = mongoose.model('Test', new Schema({ name: String }));
// Will just hang until mongoose successfully connects
MyModel.findOne();
const promise = MyModel.findOne();

setTimeout(function() {
mongoose.connect('mongodb://127.0.0.1:27017/myapp');
}, 60000);

// Will just hang until mongoose successfully connects
await promise;
```

To disable buffering, turn off the [`bufferCommands` option on your schema](guide.html#bufferCommands).
Expand Down

0 comments on commit 196c822

Please # to comment.