Skip to content

Commit 6b12a5f

Browse files
author
Chris Cho
committed
Guided Quick Start
wip small fixes add titles consolidate install, add buttons updates button format test hlist test cta alternate format fix button fix button convert to admonition change format troubleshooting reformat test wip edit text, add source constant capitalization restructure as quick start, separate connection string step fix toc edits edits
1 parent 9086828 commit 6b12a5f

18 files changed

+293
-216
lines changed

snooty.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ sharedinclude_root = "https://raw.githubusercontent.com/10gen/docs-shared/main/"
1919
version = "5.0"
2020
package-name-org = "mongodb-org"
2121
api = "https://mongodb.github.io/node-mongodb-native/{+version+}"
22+
min-node-version = "v12"
2223
mongosh = "``mongosh``"
2324
driver = "node"
2425
driver-long = "MongoDB Node.js driver"
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
.. procedure::
2+
:style: connected
3+
4+
.. step:: Create your Node.js Application
5+
6+
Create a file to contain your application called ``index.js`` in your
7+
``node_quickstart`` project directory.
8+
9+
Copy and paste the following code into the ``index.js`` file:
10+
11+
.. code-block:: js
12+
13+
const { MongoClient } = require("mongodb");
14+
15+
// Replace the uri string with your connection string.
16+
const uri = "<connection string uri>";
17+
18+
const client = new MongoClient(uri);
19+
20+
async function run() {
21+
try {
22+
const database = client.db('sample_mflix');
23+
const movies = database.collection('movies');
24+
25+
// Query for a movie that has the title 'Back to the Future'
26+
const query = { title: 'Back to the Future' };
27+
const movie = await movies.findOne(query);
28+
29+
console.log(movie);
30+
} finally {
31+
// Ensures that the client will close when you finish/error
32+
await client.close();
33+
}
34+
}
35+
run().catch(console.dir);
36+
37+
.. step:: Assign the Connection String
38+
39+
Replace the ``<connection string uri>`` placeholder in
40+
``index.js`` with the connection string that you
41+
copied from the :ref:`quick-start-connection-string` step
42+
in this guide.
43+
44+
.. step:: Run your Node.js Application
45+
46+
Run the application you created from the previous step from the
47+
command line:
48+
49+
.. code-block:: none
50+
51+
node index.js
52+
53+
You should see the details of the retrieved movie document in the output:
54+
55+
.. code-block:: none
56+
57+
{
58+
_id: ...,
59+
plot: 'A young man is accidentally sent 30 years into the past...',
60+
genres: [ 'Adventure', 'Comedy', 'Sci-Fi' ],
61+
...
62+
title: 'Back to the Future',
63+
...
64+
}
65+
66+
If you encounter an error or no output, check whether you specified the
67+
proper connection string in the application code, and loaded the sample
68+
data set in your Atlas cluster.
69+
70+
After completing this step, you should have a working application that
71+
uses the driver to connect to your MongoDB instance, runs a query on
72+
the sample data, and prints out the result.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Create a free tier MongoDB cluster on MongoDB Atlas to store and manage
2+
your data. MongoDB Atlas hosts and manages your MongoDB database in the
3+
cloud. Complete the :atlas:`Get Started with Atlas </getting-started?tck=docs_driver_nodejs>`
4+
guide to set up a new Atlas account, a free tier cluster (a shared
5+
MongoDB instance) and load sample data into your cluster.
6+
7+
Save your database username and password to a safe location for use
8+
in an upcoming step.
9+
10+
When you successfully complete the steps in the Atlas guide, you should
11+
have a new MongoDB cluster, database user, and sample data loaded in
12+
your MongoDB cluster.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
You can connect to your MongoDB cluster by providing a
2+
**connection string** which instructs the driver on where and how to
3+
connect. The connection string includes the hostname or IP address and
4+
port of your cluster, the authentication mechanism, user credentials
5+
when applicable, and connection options.
6+
7+
To connect to an instance or cluster not hosted on Atlas, see
8+
:ref:`Other Ways to Connect to MongoDB <node-other-ways-to-connect>`.
9+
10+
To retrieve your connection string for the cluster you created in
11+
the previous step, log into your Atlas account and navigate to the
12+
:guilabel:`Database` section and click the :guilabel:`Connect` button
13+
for the cluster that you want to connect to as shown in the following
14+
screenshot:
15+
16+
.. figure:: /includes/figures/atlas_connection_select_cluster.png
17+
:alt: The connect button in the clusters section of the Atlas UI
18+
19+
Proceed to the :guilabel:`Connect your application` section and select
20+
the {+driver-short+}.
21+
22+
Select the :guilabel:`Password (SCRAM)` authentication mechanism.
23+
24+
Deselect the :guilabel:`Include full driver code example` to view
25+
only the connection string.
26+
27+
Click the button on the right of the connection string to copy it to
28+
your clipboard as shown in the following screenshot:
29+
30+
.. figure:: /includes/figures/atlas_connection_copy_string_node.png
31+
:alt: The connection string copy button in the Atlas UI
32+
33+
Paste this connection string into a a file in your preferred text editor
34+
and replace the "<username>" and "<password>" placeholders with
35+
your database username and password from the previous step.
36+
37+
Save this file to a safe location.
38+
39+
After completing this step, you should have a connection string that
40+
contains your database username and password.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
First, in your shell, create a directory for your project:
2+
3+
.. code-block:: bash
4+
5+
mkdir node_quickstart
6+
7+
Then, navigate into that directory:
8+
9+
.. code-block:: bash
10+
11+
cd node_quickstart
12+
13+
Next, initialize your project:
14+
15+
.. code-block:: bash
16+
17+
npm init -y
18+
19+
When this command successfully completes, you should have a ``package.json``
20+
file in your ``node_quickstart`` directory.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Install Node and npm
2+
~~~~~~~~~~~~~~~~~~~~
3+
4+
Ensure you have Node.js {+min-node-version+} or later and
5+
npm (Node Package Manager) installed in your development environment.
6+
7+
For information on how to install Node.js and npm, see
8+
`downloading and installing Node.js and npm <https://docs.npmjs.com/downloading-and-installing-node-js-and-npm>`__.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Install the Node.js Driver
2+
--------------------------
3+
4+
.. code-block:: bash
5+
6+
npm install mongodb@{+version+}
7+
8+
This command performs the following actions:
9+
10+
- Downloads the ``mongodb`` package and the dependencies it requires
11+
- Saves the package in the ``node_modules`` directory
12+
- Records the dependency information in the ``package.json`` file
13+
14+
At this point, you are ready to use the {+driver-short+} with your
15+
application.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
In this tutorial, you created a Node.js application that
2+
connects to a MongoDB deployment hosted on MongoDB Atlas,
3+
and retrieves a document that matches a query.
4+
5+
To learn more about the MongoDB read and write operations that you
6+
can call from the {+driver-short+}, discover how to perform read
7+
and write operations in the :ref:`CRUD Operations <node-crud-landing>`
8+
section or see examples of frequently-used operations in the
9+
:ref:`Usage Examples <node-usage-examples>` section.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. note::
2+
3+
If you run into issues on this step, ask for help in the
4+
:community-forum:`MongoDB Community Forums <tag/node-js/>`
5+
or submit feedback using the :guilabel:`Share Feedback`
6+
tab on the right or bottom right side of this page.

source/index.txt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ You can add the driver to your application to work with MongoDB
3232
in JavaScript. Download it using `npm <https://www.npmjs.com/>`__
3333
or set up a runnable project by following our Quick Start guide.
3434

35-
3635
Quick Start
37-
-----------
36+
------------------
3837

3938
Learn how to establish a connection to MongoDB Atlas and begin
40-
working with data in the :doc:`Quick Start </quick-start>` section.
39+
working with data in the step-by-step :doc:`Quick Start </quick-start>`.
4140

4241
Quick Reference
4342
---------------
@@ -60,8 +59,8 @@ API
6059
---
6160

6261
For detailed information about classes and methods in the MongoDB
63-
Node.js driver, see the `MongoDB Node.js driver API documentation
64-
<{+api+}>`__ .
62+
Node.js driver, see the `{+driver-long+} API documentation
63+
<{+api+}>`__.
6564

6665
FAQ
6766
---
@@ -73,15 +72,14 @@ section.
7372
Issues & Help
7473
-------------
7574

76-
Learn how to report bugs, contribute to the driver, and find
77-
additional resources for asking questions and receiving help in the
75+
Learn how to report bugs, contribute to the driver, and to find help in the
7876
:doc:`Issues & Help </issues-and-help>` section.
7977

8078
Compatibility
8179
-------------
8280

83-
For the compatibility charts that show the recommended Node.js
84-
Driver version for each MongoDB Server version, see the
81+
For the compatibility tables that show the recommended {+driver-short+}
82+
version for each MongoDB Server version, see the
8583
:doc:`Compatibility </compatibility>` section.
8684

8785
What's New
@@ -94,19 +92,18 @@ Learn
9492
-----
9593

9694
Visit the Developer Hub and MongoDB University to learn more about the
97-
MongoDB Node.js driver.
95+
{+driver-short+}.
9896

9997
Developer Hub
10098
~~~~~~~~~~~~~
10199

102-
The Developer Hub provides tutorials and social engagement for
103-
developers.
100+
The Developer Hub provides tutorials and social engagement for developers.
104101

105102
To learn how to use MongoDB features with the Node.js driver, see the
106-
`How To's and Articles page <https://developer.mongodb.com/learn/?content=Articles&text=Node.js>`_.
103+
`How To's and Articles page <https://www.mongodb.com/developer/search/?s=Node.js>`__.
107104

108105
To ask questions and engage in discussions with fellow developers using
109-
the Node.js driver, see the `forums page <https://developer.mongodb.com/community/forums/tag/node-js>`_.
106+
the {+driver-short+}, see the `Developer Community forums <https://www.mongodb.com/community/forums/tag/node-js>`__.
110107

111108
MongoDB University
112109
~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)