Skip to content

Commit 2c3579d

Browse files
authored
Merge branch 'main' into DRIVERS-2711-POC
2 parents 95e7851 + 13bf3c9 commit 2c3579d

File tree

12 files changed

+133
-133
lines changed

12 files changed

+133
-133
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ These are the commit types we make use of:
9797
Below are some conventions that aren't enforced by any of our tooling but we nonetheless do our best to adhere to:
9898

9999
- **Disallow `export default` syntax**
100-
- For our use case it is best if all imports / exports remain named.
100+
- For our use case, it is best if all imports / exports remain named.
101101
- **As of 4.0 all code in src is in Typescript**
102102
- Typescript provides a nice developer experience.
103103
As a product of using TS, we should be using ES6 syntax features whenever possible.

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ The following table describes add-on component version compatibility for the Nod
6464

6565
We recommend using the latest version of typescript, however we currently ensure the driver's public types compile against `[email protected]`.
6666
This is the lowest typescript version guaranteed to work with our driver: older versions may or may not work - use at your own risk.
67-
Since typescript [does not restrict breaking changes to major versions](https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes) we consider this support best effort.
68-
If you run into any unexpected compiler failures against our supported TypeScript versions please let us know by filing an issue on our [JIRA](https://jira.mongodb.org/browse/NODE).
67+
Since typescript [does not restrict breaking changes to major versions](https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes), we consider this support best effort.
68+
If you run into any unexpected compiler failures against our supported TypeScript versions, please let us know by filing an issue on our [JIRA](https://jira.mongodb.org/browse/NODE).
6969

7070
## Installation
7171

@@ -153,13 +153,13 @@ Add code to connect to the server and the database **myProject**:
153153

154154
> **NOTE:** Resolving DNS Connection issues
155155
>
156-
> Node.js 18 changed the default DNS resolution ordering from always prioritizing ipv4 to the ordering
156+
> Node.js 18 changed the default DNS resolution ordering from always prioritizing IPv4 to the ordering
157157
> returned by the DNS provider. In some environments, this can result in `localhost` resolving to
158-
> an ipv6 address instead of ipv4 and a consequent failure to connect to the server.
158+
> an IPv6 address instead of IPv4 and a consequent failure to connect to the server.
159159
>
160160
> This can be resolved by:
161161
>
162-
> - specifying the ip address family using the MongoClient `family` option (`MongoClient(<uri>, { family: 4 } )`)
162+
> - specifying the IP address family using the MongoClient `family` option (`MongoClient(<uri>, { family: 4 } )`)
163163
> - launching mongod or mongos with the ipv6 flag enabled ([--ipv6 mongod option documentation](https://www.mongodb.com/docs/manual/reference/program/mongod/#std-option-mongod.--ipv6))
164164
> - using a host of `127.0.0.1` in place of localhost
165165
> - specifying the DNS resolution ordering with the `--dns-resolution-order` Node.js command line argument (e.g. `node --dns-resolution-order=ipv4first`)
@@ -224,7 +224,7 @@ console.log('Found documents =>', findResult);
224224
```
225225

226226
This query returns all the documents in the **documents** collection.
227-
If you add this below the insertMany example you'll see the document's you've inserted.
227+
If you add this below the insertMany example, you'll see the documents you've inserted.
228228

229229
### Find Documents with a Query Filter
230230

@@ -272,7 +272,7 @@ For more detailed information, see the [indexing strategies page](https://www.mo
272272

273273
## Error Handling
274274

275-
If you need to filter certain errors from our driver we have a helpful tree of errors described in [etc/notes/errors.md](https://github.com/mongodb/node-mongodb-native/blob/HEAD/etc/notes/errors.md).
275+
If you need to filter certain errors from our driver, we have a helpful tree of errors described in [etc/notes/errors.md](https://github.com/mongodb/node-mongodb-native/blob/HEAD/etc/notes/errors.md).
276276

277277
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.
278278
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.
@@ -298,14 +298,14 @@ try {
298298

299299
## Nightly releases
300300

301-
If you need to test with a change from the latest `main` branch our `mongodb` npm package has nightly versions released under the `nightly` tag.
301+
If you need to test with a change from the latest `main` branch, our `mongodb` npm package has nightly versions released under the `nightly` tag.
302302

303303
```sh
304304
npm install mongodb@nightly
305305
```
306306

307307
Nightly versions are published regardless of testing outcome.
308-
This means there could be sematic breakages or partially implemented features.
308+
This means there could be semantic breakages or partially implemented features.
309309
The nightly build is not suitable for production use.
310310

311311
## Next Steps

docs/_sources/api-articles/nodekoarticle1.txt

+50-50
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
A Basic introduction to Mongo DB
1+
A Basic introduction to MongoDB
22
================================
33

4-
Mongo DB has rapidly grown to become a popular database for web
4+
MongoDB has rapidly grown to become a popular database for web
55
applications and is a perfect fit for Node.JS applications, letting you
66
write Javascript for the client, backend and database layer. Its
77
schemaless nature is a better match to our constantly evolving data
@@ -20,14 +20,14 @@ or go fetch it from github at
2020
`https://github.com/mongodb/node-mongodb-native <https://github.com/mongodb/node-mongodb-native>`_
2121

2222
Once this business is taken care of, let's move through the types
23-
available for the driver and then how to connect to your Mongo DB
23+
available for the driver and then how to connect to your MongoDB
2424
instance before facing the usage of some CRUD operations.
2525

26-
Mongo DB data types
26+
MongoDB data types
2727
-------------------
2828

29-
So there is an important thing to keep in mind when working with Mongo
30-
DB, and that is the slight mapping difference between types Mongo DB
29+
So there is an important thing to keep in mind when working with MongoDB,
30+
and that is the slight mapping difference between types MongoDB
3131
supports and native Javascript data types. Let's have a look at the
3232
types supported out of the box and then how types are promoted by the
3333
driver to fit as close to native Javascript types as possible.
@@ -42,16 +42,16 @@ driver to fit as close to native Javascript types as possible.
4242
integer value is at a 53 bit. Mongo has two types for integers, a 32
4343
bit and a 64 bit. The driver will try to fit the value into 32 bits
4444
if it can and promote it to 64 bits if it has to. Similarly it will
45-
deserialize attempting to fit it into 53 bits if it can. If it cannot
45+
deserialize attempting to fit it into 53 bits if it can. If it cannot,
4646
it will return an instance of **Long** to avoid losing precision.
4747
- **Long class** a special class that lets you store 64 bit integers
4848
and also lets you operate on the 64 bit integers.
4949
- **Date** maps directly to a Javascript Date
5050
- **RegExp** maps directly to a Javascript RegExp
5151
- **String** maps directly to a Javascript String (encoded in utf8)
52-
- **Binary class** a special class that lets you store data in Mongo DB
53-
- **Code class** a special class that lets you store javascript
54-
functions in Mongo DB, can also provide a scope to run the method in
52+
- **Binary class** a special class that lets you store data in MongoDB
53+
- **Code class** a special class that lets you store Javascript
54+
functions in MongoDB, can also provide a scope to run the method in
5555
- **ObjectID class** a special class that holds a MongoDB document
5656
identifier (the equivalent to a Primary key)
5757
- **DbRef class** a special class that lets you include a reference in
@@ -63,13 +63,13 @@ driver to fit as close to native Javascript types as possible.
6363
As we see the number type can be a little tricky due to the way integers
6464
are implemented in Javascript. The latest driver will do correct
6565
conversion up to 53 bits of complexity. If you need to handle big
66-
integers the recommendation is to use the Long class to operate on the
66+
integers, the recommendation is to use the Long class to operate on the
6767
numbers.
6868

6969
Getting that connection to the database
7070
---------------------------------------
7171

72-
Let's get around to setting up a connection with the Mongo DB database.
72+
Let's get around to setting up a connection with the MongoDB database.
7373
Jumping straight into the code let's do direct connection and then look
7474
at the code.
7575

@@ -86,9 +86,9 @@ at the code.
8686
});
8787

8888
Let's have a quick look at how the connection code works. The
89-
**Db.connect** method let's use use a uri to connect to the Mongo
89+
**Db.connect** method lets us use a uri to connect to the Mongo
9090
database, where **localhost:27017** is the server host and port and
91-
**exampleDb** the db we wish to connect to. After the url notice the
91+
**exampleDb** the db we wish to connect to. After the url, notice the
9292
hash containing the **auto\_reconnect** key. Auto reconnect tells the
9393
driver to retry sending a command to the server if there is a failure
9494
during its execution.
@@ -103,12 +103,12 @@ dispatch and read from the tcp connection.
103103
We are up and running with a connection to the database. Let's move on
104104
and look at what collections are and how they work.
105105

106-
Mongo DB and Collections
106+
MongoDB and Collections
107107
------------------------
108108

109109
Collections are the equivalent of tables in traditional databases and
110110
contain all your documents. A database can have many collections. So how
111-
do we go about defining and using collections. Well there are a couple
111+
do we go about defining and using collections. Well, there are a couple
112112
of methods that we can use. Let's jump straight into code and then look
113113
at the code.
114114

@@ -154,7 +154,7 @@ check if the collection exists and issue an error if it does not.
154154

155155
db.createCollection('test', function(err, collection) {});
156156

157-
This command will create the collection on the Mongo DB database before
157+
This command will create the collection on the MongoDB database before
158158
returning the collection object. If the collection already exists it
159159
will ignore the creation of the collection.
160160

@@ -165,13 +165,13 @@ will ignore the creation of the collection.
165165
The **{strict:true}** option will make the method return an error if the
166166
collection already exists.
167167

168-
With an open db connection and a collection defined we are ready to do
168+
With an open db connection and a collection defined, we are ready to do
169169
some CRUD operation on the data.
170170

171171
And then there was CRUD
172172
-----------------------
173173

174-
So let's get dirty with the basic operations for Mongo DB. The Mongo DB
174+
So let's get dirty with the basic operations for MongoDB. The MongoDB
175175
wire protocol is built around 4 main operations
176176
**insert/update/remove/query**. Most operations on the database are
177177
actually queries with special json objects defining the operation on the
@@ -203,15 +203,15 @@ insert first and do it with some code.
203203
});
204204

205205
A couple of variations on the theme of inserting a document as we can
206-
see. To understand why it's important to understand how Mongo DB works
206+
see. To understand why it's important to understand how MongoDB works
207207
during inserts of documents.
208208

209-
Mongo DB has asynchronous **insert/update/remove** operations. This
210-
means that when you issue an **insert** operation its a fire and forget
209+
MongoDB has asynchronous **insert/update/remove** operations. This
210+
means that when you issue an **insert** operation, it's a fire and forget
211211
operation where the database does not reply with the status of the
212-
insert operation. To retrieve the status of the operation you have to
212+
insert operation. To retrieve the status of the operation, you have to
213213
issue a query to retrieve the last error status of the connection. To
214-
make it simpler to the developer the driver implements the **{w:1}**
214+
make it simpler to the developer, the driver implements the **{w:1}**
215215
options so that this is done automatically when inserting the document.
216216
**{w:1}** becomes especially important when you do **update** or
217217
**remove** as otherwise it's not possible to determine the amount of
@@ -225,7 +225,7 @@ above.
225225
collection.insert(doc1);
226226

227227
Taking advantage of the async behavior and not needing confirmation
228-
about the persisting of the data to Mongo DB we just fire off the insert
228+
about the persisting of the data to MongoDB, we just fire off the insert
229229
(we are doing live analytics, loosing a couple of records does not
230230
matter).
231231

@@ -244,10 +244,10 @@ A batch insert of document with any errors being reported. This is much
244244
more efficient if you need to insert large batches of documents as you
245245
incur a lot less overhead.
246246

247-
Right that's the basics of insert's ironed out. We got some documents in
247+
Right, that's the basics of insert's ironed out. We got some documents in
248248
there but want to update them as we need to change the content of a
249249
field. Let's have a look at a simple example and then we will dive into
250-
how Mongo DB updates work and how to do them efficiently.
250+
how MongoDB updates work and how to do them efficiently.
251251

252252
**the requires and and other initializing stuff omitted for brevity**
253253

@@ -274,11 +274,11 @@ how Mongo DB updates work and how to do them efficiently.
274274
});
275275
});
276276

277-
Alright before we look at the code we want to understand how document
277+
Alright, before we look at the code, we want to understand how document
278278
updates work and how to do the efficiently. The most basic and less
279279
efficient way is to replace the whole document, this is not really the
280-
way to go if you want to change just a field in your document. Luckily
281-
Mongo DB provides a whole set of operations that let you modify just
280+
way to go if you want to change just a field in your document. Luckily,
281+
MongoDB provides a whole set of operations that let you modify just
282282
pieces of the document `Atomic operations
283283
documentation <www.mongodb.com/docs/display/DOCS/Atomic+Operations>`_.
284284
Basically outlined below.
@@ -288,25 +288,25 @@ Basically outlined below.
288288
- $unset - delete a particular field (v1.3+)
289289
- $push - append a value to an array
290290
- $pushAll - append several values to an array
291-
- $addToSet - adds value to the array only if its not in the array
291+
- $addToSet - adds value to the array only if it's not in the array
292292
already
293293
- $pop - removes the last element in an array
294294
- $pull - remove a value(s) from an existing array
295295
- $pullAll - remove several value(s) from an existing array
296296
- $rename - renames the field
297297
- $bit - bitwise operations
298298

299-
Now that the operations are outline let's dig into the specific cases
299+
Now that the operations are outline, let's dig into the specific cases
300300
show in the code example.
301301

302302
::
303303

304304
collection.update({mykey:1}, {$set:{fieldtoupdate:2}}, {w:1}, function(err, result) {});
305305

306-
Right so this update will look for the document that has a field
306+
Right, so this update will look for the document that has a field
307307
**mykey** equal to **1** and apply an update to the field
308308
**fieldtoupdate** setting the value to **2**. Since we are using the
309-
**{w:1}** option the result parameter in the callback will return the
309+
**{w:1}** option, the result parameter in the callback will return the
310310
value **1** indicating that 1 document was modified by the update
311311
statement.
312312

@@ -316,9 +316,9 @@ statement.
316316

317317
This updates adds another document to the field **docs** in the document
318318
identified by **{mykey:2}** using the atomic operation **$push**. This
319-
allows you to modify keep such structures as queues in Mongo DB.
319+
allows you to modify keep such structures as queues in MongoDB.
320320

321-
Let's have a look at the remove operation for the driver. As before
321+
Let's have a look at the remove operation for the driver. As before,
322322
let's start with a piece of code.
323323

324324
**the requires and and other initializing stuff omitted for brevity**
@@ -351,7 +351,7 @@ Let's examine the 3 remove variants and what they do.
351351

352352
collection.remove({mykey:1});
353353

354-
This leverages the fact that Mongo DB is asynchronous and that it does
354+
This leverages the fact that MongoDB is asynchronous and that it does
355355
not return a result for **insert/update/remove** to allow for
356356
**synchronous** style execution. This particular remove query will
357357
remove the document where **mykey** equals **1**.
@@ -361,7 +361,7 @@ remove the document where **mykey** equals **1**.
361361
collection.remove({mykey:2}, {w:1}, function(err, result) {});
362362

363363
This remove statement removes the document where **mykey** equals **2**
364-
but since we are using **{w:1}** it will back to Mongo DB to get the
364+
but since we are using **{w:1}**, it will back to MongoDB to get the
365365
status of the remove operation and return the number of documents
366366
removed in the result variable.
367367

@@ -375,15 +375,15 @@ Time to Query
375375
-------------
376376

377377
Queries is of course a fundamental part of interacting with a database
378-
and Mongo DB is no exception. Fortunately for us it has a rich query
378+
and MongoDB is no exception. Fortunately, for us it has a rich query
379379
interface with cursors and close to SQL concepts for slicing and dicing
380-
your datasets. To build queries we have lots of operators to choose from
381-
`Mongo DB advanced
380+
your datasets. To build queries, we have lots of operators to choose from
381+
`MongoDB advanced
382382
queries <www.mongodb.com/docs/display/DOCS/Advanced+Queries>`_. There
383383
are literarily tons of ways to search and ways to limit the query. Let's
384384
look at some simple code for dealing with queries in different ways.
385385

386-
**the requires and and other initializing stuff omitted for brevity**
386+
**the requires and other initializing stuff omitted for brevity**
387387

388388
::
389389

@@ -410,11 +410,11 @@ look at some simple code for dealing with queries in different ways.
410410
});
411411
});
412412

413-
Before we start picking apart the code there is one thing that needs to
413+
Before we start picking apart the code, there is one thing that needs to
414414
be understood, the **find** method does not execute the actual query. It
415415
builds an instance of **Cursor** that you then use to retrieve the data.
416-
This lets you manage how you retrieve the data from Mongo DB and keeps
417-
state about your current Cursor state on Mongo DB. Now let's pick apart
416+
This lets you manage how you retrieve the data from MongoDB and keeps
417+
state about your current Cursor state on MongoDB. Now let's pick apart
418418
the queries we have here and look at what they do.
419419

420420
::
@@ -425,7 +425,7 @@ This query will fetch all the document in the collection and return them
425425
as an array of items. Be careful with the function **toArray** as it
426426
might cause a lot of memory usage as it will instantiate all the
427427
document into memory before returning the final array of items. If you
428-
have a big resultset you could run into memory issues.
428+
have a big resultset, you could run into memory issues.
429429

430430
::
431431

@@ -448,10 +448,10 @@ done.
448448
This is special supported function to retrieve just one specific
449449
document bypassing the need for a cursor object.
450450

451-
That's pretty much it for the quick intro on how to use the database. I
451+
That's pretty much info for the quick intro on how to use the database. I
452452
have also included a list of links to where to go to find more
453-
information and also a sample crude location application I wrote using
454-
express JS and mongo DB.
453+
information and also a sample CRUD location application I wrote using
454+
express JS and MongoDB.
455455

456456
Links and stuff
457457
---------------
@@ -460,7 +460,7 @@ Links and stuff
460460
usage <https://github.com/mongodb/node-mongodb-native/tree/master/examples>`_
461461
- `All the integration tests, they have tons of different usage
462462
cases <https://github.com/mongodb/node-mongodb-native/tree/master/test>`_
463-
- `The Mongo DB wiki pages such as the advanced query
463+
- `The MongoDB wiki pages such as the advanced query
464464
link <www.mongodb.com/docs/display/DOCS/Advanced+Queries>`_
465465
- `A silly simple location based application using Express JS and Mongo
466466
DB <https://github.com/christkv/mongodb-presentation>`_

0 commit comments

Comments
 (0)