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
Some of these packages include native C++ extensions, consult the [trouble shooting guide here](https://github.com/mongodb/node-mongodb-native/blob/4.0/docs/native-extensions.md) if you run into issues.
75
+
Some of these packages include native C++ extensions, consult the [trouble shooting guide here](https://github.com/mongodb/node-mongodb-native/blob/4.1/docs/native-extensions.md) if you run into issues.
76
76
77
77
## Quick Start
78
78
@@ -126,33 +126,33 @@ Add code to connect to the server and the database **myProject**:
126
126
> if a callback is provided a Promise will not be returned.
127
127
128
128
```js
129
-
const { MongoClient } =require('mongodb')
129
+
const { MongoClient } =require('mongodb');
130
130
// or as an es module:
131
131
// import { MongoClient } from 'mongodb'
132
132
133
133
// Connection URL
134
-
consturl='mongodb://localhost:27017'
135
-
constclient=newMongoClient(url)
134
+
consturl='mongodb://localhost:27017';
135
+
constclient=newMongoClient(url);
136
136
137
137
// Database Name
138
-
constdbName='myProject'
138
+
constdbName='myProject';
139
139
140
140
asyncfunctionmain() {
141
141
// Use connect method to connect to the server
142
-
awaitclient.connect()
143
-
console.log('Connected successfully to server')
144
-
constdb=client.db(dbName)
145
-
constcollection=db.collection('documents')
142
+
awaitclient.connect();
143
+
console.log('Connected successfully to server');
144
+
constdb=client.db(dbName);
145
+
constcollection=db.collection('documents');
146
146
147
147
// the following code examples can be pasted here...
148
148
149
-
return'done.'
149
+
return'done.';
150
150
}
151
151
152
152
main()
153
153
.then(console.log)
154
154
.catch(console.error)
155
-
.finally(() =>client.close())
155
+
.finally(() =>client.close());
156
156
```
157
157
158
158
Run your app from the command line with:
@@ -169,8 +169,8 @@ Add to **app.js** the following function which uses the **insertMany**
169
169
method to add three documents to the **documents** collection.
The method updates the first document where the field **a** is equal to **3** by adding a new field **b** to the document set to **1**. `updateResult` contains information about whether there was a matching document to update or not.
@@ -214,8 +214,8 @@ The method updates the first document where the field **a** is equal to **3** by
214
214
Remove the document where the field **a** is equal to **3**.
For more detailed information, see the [indexing strategies page](https://docs.mongodb.com/manual/applications/indexes/).
233
233
234
+
## Error Handling
235
+
236
+
If you need to filter certain errors from our driver we have a helpful tree of errors described in [docs/errors.md](https://github.com/mongodb/node-mongodb-native/blob/4.1/docs/errors.md).
237
+
238
+
It is our recommendation to use `instanceof` checks on errors and to avoid relying on parsing `error.message` and `error.name` strings in your code.
239
+
We guarantee `instanceof` checks will pass according to semver guidelines, but errors may be sub-classed or their messages may change at any time, even patch releases, as we see fit to increase the helpfulness of the errors.
240
+
241
+
Any new errors we add to the driver will directly extend an existing error class and no existing error will be moved to a different parent class outside of a major release.
242
+
This means `instanceof` will always be able to accurately capture the errors that our driver throws (or returns in a callback).
0 commit comments