Skip to content

Commit 69c2e08

Browse files
author
Chris Cho
authored
DOCSP-27149 guided quick start (#586)
* Guided Quick Start
1 parent d2300dd commit 69c2e08

File tree

11 files changed

+306
-209
lines changed

11 files changed

+306
-209
lines changed

config/redirects

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@ raw: ${prefix}/stable -> ${base}/current/
1111
[*-master]: ${prefix}/${version}/fundamentals/connection/lambda/ -> ${base}/${version}/fundamentals/connection/
1212
[v4.7-*]: ${prefix}/${version}/fundamentals/csfle -> ${base}/${version}/fundamentals/encrypt-fields/
1313
[*-v4.6]: ${prefix}/${version}/fundamentals/encrypt-fields -> ${base}/${version}/fundamentals/csfle/
14+
15+
[*-v5.0]: ${prefix}/${version}/quick-start/connect-to-mongodb/ -> ${base}/${version}/quick-start/
16+
[*-v5.0]: ${prefix}/${version}/quick-start/create-a-connection-string/ -> ${base}/${version}/quick-start/
17+
[*-v5.0]: ${prefix}/${version}/quick-start/create-a-deployment/ -> ${base}/${version}/quick-start/
18+
[*-v5.0]: ${prefix}/${version}/quick-start/download-and-install/ -> ${base}/${version}/quick-start/
19+
[*-v5.0]: ${prefix}/${version}/quick-start/next-steps/ -> ${base}/${version}/quick-start/
20+

snooty.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ toc_landing_pages = [
1212
"/fundamentals/connection",
1313
"/fundamentals/crud",
1414
"/usage-examples",
15+
"/quick-start",
1516
]
1617
sharedinclude_root = "https://raw.githubusercontent.com/10gen/docs-shared/main/"
1718

1819
[constants]
1920
version = "5.1"
2021
package-name-org = "mongodb-org"
2122
api = "https://mongodb.github.io/node-mongodb-native/{+version+}"
23+
min-node-version = "v12"
2224
mongosh = "``mongosh``"
2325
driver = "node"
2426
driver-long = "MongoDB Node.js driver"
5.07 KB
Loading
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: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ MongoDB Node Driver
44

55
.. _node-driver-landing:
66

7-
.. default-domain:: mongodb
8-
9-
.. include:: /includes/unicode-checkmark.rst
10-
117
.. toctree::
128
:titlesonly:
139
:maxdepth: 1
@@ -32,12 +28,11 @@ You can add the driver to your application to work with MongoDB
3228
in JavaScript. Download it using `npm <https://www.npmjs.com/>`__
3329
or set up a runnable project by following our Quick Start guide.
3430

35-
3631
Quick Start
3732
-----------
3833

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

4237
Quick Reference
4338
---------------
@@ -60,8 +55,8 @@ API
6055
---
6156

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

6661
FAQ
6762
---
@@ -73,15 +68,14 @@ section.
7368
Issues & Help
7469
-------------
7570

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

8074
Compatibility
8175
-------------
8276

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

8781
What's New
@@ -94,19 +88,18 @@ Learn
9488
-----
9589

9690
Visit the Developer Hub and MongoDB University to learn more about the
97-
MongoDB Node.js driver.
91+
{+driver-short+}.
9892

9993
Developer Hub
10094
~~~~~~~~~~~~~
10195

102-
The Developer Hub provides tutorials and social engagement for
103-
developers.
96+
The Developer Hub provides tutorials and social engagement for developers.
10497

10598
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>`_.
99+
`How To's and Articles page <https://www.mongodb.com/developer/search/?s=Node.js>`__.
107100

108101
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>`_.
102+
the {+driver-short+}, see the `Developer Community forums <https://www.mongodb.com/community/forums/tag/node-js>`__.
110103

111104
MongoDB University
112105
~~~~~~~~~~~~~~~~~~

source/quick-start.txt

Lines changed: 18 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -4,211 +4,37 @@
44
Quick Start
55
===========
66

7-
.. default-domain:: mongodb
8-
97
.. contents:: On this page
108
:local:
119
:backlinks: none
12-
:depth: 2
10+
:depth: 1
1311
:class: singlecol
1412

13+
Overview
14+
--------
15+
1516
This guide shows you how to create an application that uses the
1617
{+driver-long+} to connect to a MongoDB cluster hosted on MongoDB Atlas. If
1718
you prefer to connect to MongoDB using a different driver or programming
1819
language, see our :driver:`list of official drivers <>`.
1920

20-
The {+driver-short+} is a library you can use to connect to and communicate
21-
with MongoDB.
21+
The {+driver-short+} is a library of functions that you can use to connect
22+
to and communicate with MongoDB.
2223

2324
MongoDB Atlas is a fully managed cloud database service that hosts your
24-
MongoDB servers. You can get started with your own free (no credit card
25-
required) MongoDB instance with this guide.
26-
27-
Follow the steps below to connect a sample Node.js application to a MongoDB
28-
instance on MongoDB Atlas.
29-
30-
Set up Your Project
31-
-------------------
32-
33-
Install Node and npm
34-
~~~~~~~~~~~~~~~~~~~~
35-
36-
Ensure you have Node.js v12 or later and npm (Node Package Manager) installed
37-
in your development environment.
38-
39-
For information on how to install Node.js and npm, see
40-
`downloading and installing Node.js and npm <https://docs.npmjs.com/downloading-and-installing-node-js-and-npm>`__.
41-
42-
43-
Create the Project
44-
~~~~~~~~~~~~~~~~~~
45-
46-
First, in your shell, create a directory for your project:
47-
48-
.. code-block:: bash
49-
50-
mkdir node_quickstart
51-
52-
Then, navigate into that directory:
53-
54-
.. code-block:: bash
55-
56-
cd node_quickstart
57-
58-
Next, initialize your project:
59-
60-
.. code-block:: bash
61-
62-
npm init -y
63-
64-
Add MongoDB as a Dependency
65-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
66-
67-
Install the {+driver-short+}:
68-
69-
.. code-block:: bash
70-
71-
npm install mongodb@{+version+}
72-
73-
This command performs the following actions:
74-
75-
- Downloads the ``mongodb`` package and the dependencies it requires
76-
- Saves the package in the ``node_modules`` directory
77-
- Records the dependency information in the ``package.json`` file
78-
79-
At this point, you are ready to use the {+driver-short+} with your
80-
application.
81-
82-
.. _node-quickstart-connect-cluster:
83-
84-
Create a MongoDB Cluster
85-
~~~~~~~~~~~~~~~~~~~~~~~~
86-
87-
.. procedure::
88-
:style: connected
89-
90-
.. step:: Create a Free Tier Cluster in Atlas
91-
92-
Create a free tier MongoDB cluster on MongoDB Atlas to store and manage
93-
your data. MongoDB Atlas hosts and manages your MongoDB database in the
94-
cloud. Complete the :atlas:`Get Started with Atlas </getting-started?tck=docs_driver_nodejs>`
95-
guide to set up a new Atlas account, a free tier cluster (a shared
96-
MongoDB instance) and load sample data into your cluster.
97-
98-
.. step:: Connect to your Cluster
99-
100-
You can connect to your MongoDB cluster by providing a
101-
**connection string** which instructs the driver on where and how to
102-
connect. The connection string includes information on the hostname
103-
or IP address and port of your cluster, the authentication mechanism,
104-
user credentials when applicable, and other connection options.
105-
106-
To connect to an instance or cluster not hosted on Atlas, see
107-
:ref:`Other Ways to Connect to MongoDB <node-other-ways-to-connect>`.
108-
109-
To retrieve your connection string for the cluster you created in
110-
the previous step, log into your Atlas account and navigate to the
111-
:guilabel:`Database` section and click the :guilabel:`Connect` button
112-
for the cluster that you want to connect to as shown below.
113-
114-
.. figure:: /includes/figures/atlas_connection_select_cluster.png
115-
:alt: The connect button in the clusters section of the Atlas UI
116-
117-
Proceed to the :guilabel:`Connect Your Application` section and select
118-
the {+driver-short+}. Select the :guilabel:`Connection String Only` tab
119-
and click the :guilabel:`Copy` button to copy the connection string to
120-
your clipboard as shown below.
121-
122-
.. figure:: /includes/figures/atlas_connection_copy_string_node.png
123-
:alt: The connection string copy button in the Connection String Only tab of the Atlas UI
124-
125-
Save your connection string to a safe location.
126-
127-
Connect to Your Application
128-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
129-
130-
.. procedure::
131-
:style: connected
132-
133-
.. step:: Create your Node.js Application
134-
135-
Create a file to contain your application called ``index.js`` in your
136-
project directory. Add the following code, assigning the ``uri``
137-
variable the value of your connection string.
138-
139-
140-
.. code-block:: js
141-
142-
const { MongoClient } = require("mongodb");
143-
144-
// Replace the uri string with your connection string.
145-
const uri =
146-
"mongodb+srv://<user>:<password>@<cluster-url>?retryWrites=true&w=majority";
147-
148-
const client = new MongoClient(uri);
149-
150-
async function run() {
151-
try {
152-
const database = client.db('sample_mflix');
153-
const movies = database.collection('movies');
154-
155-
// Query for a movie that has the title 'Back to the Future'
156-
const query = { title: 'Back to the Future' };
157-
const movie = await movies.findOne(query);
158-
159-
console.log(movie);
160-
} finally {
161-
// Ensures that the client will close when you finish/error
162-
await client.close();
163-
}
164-
}
165-
run().catch(console.dir);
166-
167-
.. tip::
168-
169-
The preceding code example assigns the ``MongoClient`` variable using
170-
:mdn:`object destructuring <Web/JavaScript/Reference/Operators/Destructuring_assignment#object_destructuring>`,
171-
introduced in Node.js v6. You can create an instance of a
172-
``MongoClient`` without using object destructuring as shown in the
173-
following code:
174-
175-
.. code-block:: js
176-
177-
const MongoClient = require("mongodb").MongoClient;
178-
179-
.. step:: Run your Node.js Application
180-
181-
Run the application you created from the previous step from the
182-
command line:
183-
184-
.. code-block:: none
185-
186-
node index.js
187-
188-
You should see the details of the retrieved movie document in the output:
189-
190-
.. code-block:: none
191-
192-
{
193-
_id: ...,
194-
plot: 'A young man is accidentally sent 30 years into the past...',
195-
genres: [ 'Adventure', 'Comedy', 'Sci-Fi' ],
196-
...
197-
title: 'Back to the Future',
198-
...
199-
}
25+
MongoDB deployments. You can create your own free (no credit card
26+
required) MongoDB Atlas deployment by following the steps in this guide.
20027

201-
If you encounter an error or no output, check whether you specified the
202-
proper connection string in the application code, and loaded the sample
203-
data set in your Atlas cluster.
28+
Follow the steps in this guide to connect a sample Node.js application to
29+
a MongoDB Atlas deployment.
20430

205-
At this point, you should have a working application that uses
206-
the {+driver-short+} to connect to your MongoDB instance, runs a query
207-
on the sample data, and prints out the result.
31+
.. button:: Next: Download and Install
32+
:uri: /quick-start/download-and-install/
20833

209-
Next Steps
210-
----------
34+
.. toctree::
21135

212-
Learn how to read and modify data using the {+driver-short+} in our
213-
:ref:`CRUD Operations <node-crud-landing>` guide or how to perform common
214-
operations in our :ref:`Usage Examples <node-usage-examples>`.
36+
/quick-start/download-and-install/
37+
/quick-start/create-a-deployment/
38+
/quick-start/create-a-connection-string/
39+
/quick-start/connect-to-mongodb/
40+
/quick-start/next-steps/

0 commit comments

Comments
 (0)