This is one stop global knowledge base where you can learn about all the products, solutions and support features.
On this page
One of the benefits of MongoDB’s rich schema model is the ability to store arrays as document field values. Storing arrays as field values allows you to model one-to-many or many-to-many relationships in a single document, instead of across separate collections as you might in a relational database.
However, you should exercise caution if you are consistently adding
elements to arrays in your documents. If you do not limit the number of
elements in an array, your documents may grow to an unpredictable size.
As an array continues to grow, reading and building indexes on that
array gradually decrease in performance. A large, growing array can
strain application resources and put your documents at risk of exceeding
the
BSON
Document
Size
limit.
Instead, consider bounding your arrays to improve performance and keep your documents a manageable size.
Consider the following schema for a
publishers
collection:
// publishers collection
{
"_id": "orielly"
"name": "O'Reilly Media",
"founded": 1980,
"location": "CA",
"books": [
{
"_id": 123456789,
"title": "MongoDB: The Definitive Guide",
"author": [ "Kristina Chodorow", "Mike Dirolf" ],
"published_date": ISODate("2010-09-24"),
"pages": 216,
"language": "English"
},
{
"_id": 234567890,
"title": "50 Tips and Tricks for MongoDB Developer",
"author": "Kristina Chodorow",
"published_date": ISODate("2011-05-06"),
"pages": 68,
"language": "English"
}
]
}
In this scenario, the
books
array is
unbounded
. Each new book
released by this publishing company adds a new sub-document to the
books
array. As publishing companies continue to release books, the
documents will eventually grow very large and cause a disproportionate
amount of memory strain on the application.
To avoid mutable, unbounded arrays, separate the
publishers
collection into two collections, one for
publishers
and one for
books
. Instead of embedding the entire
book
document in the
publishers
document, include a
reference
to the publisher inside of the book document:
// publishers collection
{
"_id": "oreilly"
"name": "O'Reilly Media",
"founded": 1980,
"location": "CA"
}
// books collection
{
"_id": 123456789,
"title": "MongoDB: The Definitive Guide",
"author": [ "Kristina Chodorow", "Mike Dirolf" ],
"published_date": ISODate("2010-09-24"),
"pages": 216,
"language": "English",
"publisher_id": "oreilly"
}
{
"_id": 234567890,
"title": "50 Tips and Tricks for MongoDB Developer",
"author": "Kristina Chodorow",
"published_date": ISODate("2011-05-06"),
"pages": 68,
"language": "English",
"publisher_id": "oreilly"
}
This updated schema removes the unbounded array in the
publishers
collection and places a reference to the publisher in each book document
using the
publisher_id
field. This ensures that each document has a
manageable size, and there is no risk of a document field growing
abnormally large.
$lookups
¶
This approach works especially well if your application loads the book
and publisher information separately. If your application requires the
book and information together, it needs to perform a
$lookup
operation to join the data from the
publishers
and
books
collections.
$lookup
operations are not very performant, but
in this scenario may be worth the trade off to avoid unbounded arrays.
To learn how to incorporate the flexible data model into your schema, see the following presentations from MongoDB.live 2020 :
The Performance Advisor recognizes a query as slow if it takes longer
to execute than the value of
slowOpThresholdMs.
By default, this value is
100
milliseconds. You can change the
threshold with either the
profile
command or the db.setProfilingLevel()
mongosh
method.
Example
The following
profile
command example sets the threshold at 200
milliseconds:
db.runCommand({
profile: 0,
slowOpThresholdMs: 200
})
If you are running MongoDB 3.6 or later, you can customize the
percentage of slow queries in your logs used by the Performance Advisor
by specifying the
sampleRate
parameter.
Example
This sets the slow query threshold to a lower value of 100 milliseconds but also sets the sample rate to 10%.
db.runCommand({
profile: 0,
slowOpThresholdMs: 100,
sampleRate: 0.1
})
Note
By default, the value of
profile
is
0
. MongoDB recommends
leaving this value unchanged since other values can negatively
impact database performance. To learn more, see the
profile command.
On this page
From your Context menu, click the project that has the hosts you want to configure.
Click Deployments .
Click Servers .
On the host where you want to activate Backup, click ellipsis icon .
Click Activate Backup .
From the banner, click Review & Deploy .
If you want to activate Backup, click Confirm & Deploy . Otherwise click Cancel , then Discard Changes to cancel activating Backup.
Note
Only one host can backup a deployment at a time. On the Server tab, the host that is backing up the deployment displays Backup - active . Any other host with Backup activated displays Backup - standby .
From your Context menu, click the project that has the hosts you want to configure.
Click Deployments .
Click Servers .
On the host where you want to activate Monitoring, click ellipsis icon .
Click Activate Monitoring .
From the banner, click Review & Deploy .
If you want to activate Monitoring, click Confirm & Deploy . Otherwise click Cancel , then Discard Changes to cancel activating Monitoring.
Note
Only one host can monitor a deployment at a time. On the Server tab, the host that is monitoring the deployment displays Monitoring - active . Any other host with Monitoring activated displays Monitoring - standby .
Multiple Monitoring Agents
You can activate Monitoring on multiple MongoDB Agents to distribute monitoring assignments and provide failover. Cloud Manager distributes monitoring assignments among up to 100 running MongoDB Agents. Each MongoDB Agent running active Monitoring monitors a different set of MongoDB processes. One MongoDB Agent running active Monitoring per project is the primary Monitor. The primary Monitor reports the cluster’s status to Cloud Manager. As MongoDB Agents have Monitoring enabled or disabled, Cloud Manager redistributes assignments. If the primary Monitor fails, Cloud Manager assigns another MongoDB Agent running active Monitoring to be the primary Monitor.
If you run more than 100 MongoDB Agents with active Monitoring, the additional MongoDB Agents run as standby MongoDB Agents. A standby MongoDB Agent is idle, except to log its status as a standby and periodically ask Cloud Manager if it should begin monitoring.
If you install multiple Monitoring Agents, ensure that
all
the
MongoDB Agents with active Monitoring can reach all the
mongod
processes in the deployment.
To activate Monitoring on multiple MongoDB Agents, repeat the activation process on multiple MongoDB Agents.
Automation is activated when you:
On this page
We recommend that you rotate the automation user’s password periodically. Cloud Manager provides an automated procedure for password rotation with no downtime.
To enable password rotation for the automation user, you must meet the following requirement:
Otherwise, click Cancel and you can make additional changes.
On this page
The Data Explorer provides an aggregation pipeline builder to process your data. Aggregation pipelines transform your documents into aggregated results based on selected pipeline stages.
The MongoDB Atlas aggregation pipeline builder is primarily designed for building pipelines, rather than executing them. The pipeline builder provides an easy way to export your pipeline to execute in a driver.
To interact with data in the Cloud Manager UI:
To create and execute aggregation pipelines in the
Data Explorer
, you must have been granted at least the
Project
Data
Access
Read
Only
role.
To utilize the
$out
stage in your pipeline, you must
have been granted at least the
Project
Data
Access
Read/Write
role.
The main panel and Namespaces on the left side list the collections in the database.
The main panel displays the Find , Indexes , and Aggregation views.
When you first open the Aggregation view, the Data Explorer displays an empty aggregation pipeline.
Select an aggregation stage from the Select dropdown in the bottom-left panel.
The toggle to the right of the dropdown dictates whether the stage is enabled.
Fill in your stage with the appropriate values. If Comment Mode is enabled, the pipeline builder provides syntactic guidelines for your selected stage.
As you modify your stage, the Data Explorer updates the preview documents on the right based on the results of the current stage.
There are two ways to add additional stages to your pipeline:
To delete a pipeline stage, click the trash icon icon on the desired stage.
Use collation to specify language-specific rules for string comparison, such as rules for lettercase and accent marks.
To specify a collation document, click Collation at the top of the pipeline builder.
A collation document has the following fields:
{
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
The
locale
field is mandatory; all other collation fields are
optional. For descriptions of the fields, see
Collation Document.
You can import aggregation pipelines from plain text into the pipeline builder to easily modify and verify your pipelines.
To import a pipeline from plain text:
Click the arrow next to the plus icon at the top of the pipeline builder.
Click New Pipeline from Text .
Your pipeline must match the syntax of the
pipeline
parameter of
the
db.collection.aggregate()
method.
To return your pipeline to the initial blank state, click the plus icon at the top of the pipeline builder.
You can use the aggregation pipeline builder to export your finished pipeline to one of the supported driver languages; Java, Node, C#, and Python 3. Use this feature to format and export pipelines for use in your applications.
To export your aggregation pipeline:
For instructions on creating an aggregation pipeline, see Create an Aggregation Pipeline .
In the Export Pipeline To dropdown, select your desired language.
The
My Pipeline
pane on the left displays your
pipeline in
mongosh
syntax.
The pane on the right displays your pipeline in the selected language.
(Optional) : Check the Include Import Statements option to include the required import statements for the language selected.
Click the Copy button at the top-right of the pipeline to copy the pipeline for the selected language to your clipboard. You can now integrate your pipeline into your application.
To modify the aggregation pipeline builder settings:
You can modify the following settings:
Setting | Description | Default |
---|---|---|
Comment Mode |
When enabled, the Data Explorer adds helper comments to each stage. Note Changing this setting only affects new stages and does not modify stages which have already been added to your pipeline. |
On |
Number of Preview Documents | Number of documents to show in the preview for each stage. | 20 |
Before the introduction of the MongoDB Agent, each function – Automation, Backup, and Monitoring – ran as a separate agent binary in your project.
The MongoDB Agent runs as a single binary that can perform any – or all – of the three functions depending upon what you need.
On this page
Base URL:
https://cloud.mongodb.com/api/public/v1.0
GET /orgs/{ORG-ID}/groups
Path Element | Type | Description |
---|---|---|
ORG-ID | Required. | The unique identifier for the organization whose information you want to retrieve. |
The following query parameters are optional:
Name | Type | Description | Default |
---|---|---|---|
pageNum
|
integer | Page number (1-based). |
1
|
itemsPerPage
|
integer | Number of items to return per page, up to a maximum of 500. |
100
|
pretty
|
boolean | Displays response in a prettyprint format. |
false
|
envelope
|
boolean | Specifies whether or not to wrap the response in an envelope . |
false
|
name
|
string |
Human-readable label of the project to use to filter the returned
list. Performs a case-insensitive search for a project, which is
prefixed by the specified
Example
If you specify a
|
None |
This endpoint doesn’t use HTTP request body parameters.
The response JSON document includes an array of result objects, an array of link objects and a count of the total number of result objects retrieved.
Name | Type | Description |
---|---|---|
results
|
array | Array includes one object for each item detailed in the results Embedded Document section. |
links
|
array | Array includes one or more links to sub-resources and/or related resources. The relations between URL s are explained in the Web Linking Specification . |
totalCount
|
number | Integer count of the total number of items in the result set. It may be greater than the number of objects in the results array if the entire result set is paginated. |
Each result is one project.
Name | Type | Description |
---|---|---|
activeAgentCount | integer | The number of active monitoring, automation, and Backups in the project. |
hostCounts | Document | Describes the host types and number of each host type for the cluster. |
hostCounts.arbiter | integer | The number of arbiter hosts in the cluster. |
hostCounts.config | integer | The number of sharded cluster configuration server hosts in the cluster. |
hostCounts.master | integer | The number of master hosts in the cluster. |
hostCounts.mongos | integer |
The number of
mongos
hosts in the
cluster.
|
hostCounts.primary | integer | The number of primary hosts in the cluster. |
hostCounts.secondary | integer | The number of secondary hosts in the cluster. |
hostCounts.slave | integer | The number of slave hosts in the cluster. |
id | string | The unique identifier for the project. |
links | object array |
One or more links to sub-resources and/or related resources. All
links
arrays in responses include at least one link called
self
. The relationships between
URL
s are explained in the
Web Linking Specification
.
|
name | string | The name of the cluster. |
orgId | string | The unique identifier for the parent organization of the project. |
publicApiEnabled | boolean | The status of API access to the cluster. |
replicaSetCount | integer | The number of replica sets in the cluster. |
shardCount | integer | The number of shards in the cluster. |
curl --user "{username:apiKey}" \
--include \
--header "Content-Type: application/json" \
--digest GET "https://cloud.mongodb.com/api/public/v1.0/orgs/{ORG-ID}/groups"
HTTP/1.1 401 Unauthorized
Content-Type: application/json;charset=ISO-8859-1
Date: {dateInUnixFormat}
WWW-Authenticate: Digest realm="MMS Public API", domain="", nonce="{nonce}", algorithm=MD5, op="auth", stale=false
Content-Length: {requestLengthInBytes}
Connection: keep-alive
HTTP/1.1 200 OK
Vary: Accept-Encoding
Content-Type: application/json
Strict-Transport-Security: max-age=300
Date: {dateInUnixFormat}
Connection: keep-alive
Content-Length: {requestLengthInBytes}
X-MongoDB-Service-Version: gitHash={gitHash}; versionString={ApplicationVersion}
{
"links": [{
}],
"results": [{
"activeAgentCount": 0,
"hostCounts": {
"arbiter": 0,
"config": 0,
"master": 0,
"mongos": 0,
"primary": 1,
"secondary": 2,
"slave": 0
},
"id": "{PROJECT-ID}",
"links": [{
}],
"name": "Production Cluster",
"orgId": "{ORG-ID}",
"publicApiEnabled": true,
"replicaSetCount": 1,
"shardCount": 0
},
{
"activeAgentCount": 0,
"hostCounts": {
"arbiter": 0,
"config": 0,
"master": 0,
"mongos": 0,
"primary": 1,
"secondary": 2,
"slave": 0
},
"id": "{PROJECT-ID}",
"lastActiveAgent": "2017-10-26T02:39:59Z",
"links": [{
}],
"name": "Staging Cluster",
"orgId": "{ORG-ID}",
"publicApiEnabled": true,
"replicaSetCount": 1,
"shardCount": 0
}
],
"totalCount": 2
}
On this page
Note
This feature is available only with Cloud Manager Premium, which comes with certain MongoDB subscriptions. Contact MongoDB for more information.
The Performance Advisor monitors any operation with a query predicate that MongoDB considers slow and suggests new indexes to improve query performance. For the selected host and time period, the Performance Advisor evaluates up to the 20,000 most recent slow queries found in the logs.
Recommended indexes are accompanied by sample queries, grouped by query shape , that were run against a collection that would benefit from the suggested index. The Performance Advisor does not negatively affect the performance of your Cloud Manager clusters.
Note
To view the Performance Advisor, you must:
Run MongoDB version 3.2 or later on your cluster.
Manage your cluster with MongoDB Agent Automation.
To learn more about the MongoDB Agent, see MongoDB Agent .
To view the field values in the example queries, you must be a Cloud Manager user with one or more of the following roles:
Project
Owner
Project
Data
Access
Admin
Project
Data
Access
Read/Write
Project
Data
Access
Read
Only
Users without the aforementioned roles cannot see the field values.
Required Privileges
To enable
Performance Advisor
for a project, you must
have the
Project
Owner
role for the project.
Performance Advisor is enabled by default. To disable or enable Performance Advisor:
If a query is slow, common reasons include:
Indexes improve read performance, but a large number of indexes can negatively impact write performance since indexes must be updated during writes. If your collection already has several indexes, consider this tradeoff of read and write performance when deciding whether to create new indexes. Examine whether a query for such a collection can be modified to take advantage of existing indexes, as well as whether a query occurs often enough to justify the cost of a new index.
The Performance Advisor can help identify and remove unnecessary indexes. To learn more, see Review Drop Index Recommendations .
To access the Performance Advisor :
If the replica set resides in a sharded cluster, first click the sharded cluster containing the replica set.
The Performance Advisor displays up to 20 query shapes across all collections in the cluster and suggested indexes for those shapes. The Performance Advisor ranks the indexes according to their Impact , which indicates High or Medium based on the total wasted bytes read. To learn more about index ranking, see Review Index Ranking .
Note
If the slow query log contains consecutive
$match
stages
in the aggregation pipeline, the two stages can coalesce
into the first
$match
stage and result in a single
$match
stage. As a result, the query shape in the
Performance Advisor might differ from the actual query you ran.
The Performance Advisor ranks the indexes that it suggests according to their Impact , which indicates High or Medium based on the total wasted bytes read. To learn more about how the Performance Advisor ranks indexes, see Review Index Ranking .
To learn how to create indexes that the Performance Advisor suggests, see Create Suggested Indexes .
Each index that the Performance Advisor suggests contains the following metrics. These metrics apply specifically to queries which would be improved by the index:
Metric | Description |
---|---|
Execution Count | Number of queries executed per hour which would be improved. |
Average Execution Time | Current average execution time in milliseconds for affected queries. |
Average Query Targeting | Average number of documents read per document returned by affected queries. A higher query targeting score indicates a greater degree of inefficiency. For more information on query targeting, see Query Targeting . |
In Memory Sort | Current number of affected queries per hour that needed to be sorted in memory. |
Average Docs Scanned | Average number of documents scanned. |
Average Docs Returned | Average number of documents returned. |
Avgerage Object Size | Average object size. |
For each suggested index, the Performance Advisor shows the most commonly executed query shapes that the index would improve. For each query shape, the Performance Advisor displays the following metrics:
Metric | Description |
---|---|
Execution Count | Number of queries executed per hour which match the query shape. |
Average Execution Time | Average execution time in milliseconds for queries which match the query shape. |
Average Query Targeting | Average number of documents read for every document returned by matching queries. A higher query targeting score indicates a greater degree of inefficiency. For more information on query targeting, see Query Targeting . |
Average Docs Scanned | Average number of documents scanned. |
Average Docs Returned | Average number of documents returned. |
The Performance Advisor also shows each executed sample query that matches the query shape, with specific metrics for that query.
Each index suggestion includes an Average Query Targeting score indicating how many documents were read for every document returned for the index’s corresponding query shapes. A score of 1 represents very efficient query shapes because every document read matched the query and was returned with the query results. All suggested indexes represent an opportunity to improve query performance.
By default, the Performance Advisor suggests indexes for all clusters in the deployment. To only show suggested indexes from a specific collection, use the Collection dropdown at the top of the Performance Advisor.
You can also adjust the time range the Performance Advisor takes into account when suggesting indexes by using the Time Range dropdown at the top of the Performance Advisor.
The Performance Advisor can’t suggest indexes for MongoDB databases configured to use the ctime timestamp format. As a workaround, set the timestamp format for such databases to either iso8601-utc or iso8601-local.
The Performance Advisor analyzes up to 200,000 of your cluster’s most recent log lines.
You can create indexes suggested by the Performance Advisor directly within the Performance Advisor itself. When you create indexes, keep the ratio of reads to writes on the target collection in mind. Indexes come with a performance cost, but are more than worth the cost for frequent queries on large data sets. To learn more about indexing strategies, see Indexing Strategies.
To create a suggested index:
The Performance Advisor opens the Create Index dialog and prepopulates the Fields based on the index you selected.
{ <option1>: <value1>, ... }
Example
The following options document specifies the
unique
option and
the
name
for the index:
{ unique: true, name: "myUniqueIndex" }
Use collation to specify language-specific rules for string comparison,
such as rules for lettercase and accent marks. The
collation document
contains a
locale
field which indicates the ICU Locale code, and may contain other
fields to define collation behavior.
Example
The following collation option document specifies a locale value
of
fr
for a French language collation:
{ "locale": "fr" }
To review the list of locales that MongoDB collation supports, see the list of languages and locales . To learn more about collation options, including which are enabled by default for each locale, see Collation in the MongoDB manual.
Warning
Due to critical issue SERVER-68925, Cloud Manager deployments using certain versions of the MongoDB Agent should not perform automated rolling index builds on clusters running the following MongoDB versions:
You can continue to perform manual rolling index builds safely on your clusters. To perform automated rolling index builds safely, upgrade the MongoDB Agent to 12.4.0.7703 or later or upgrade your clusters to:
Important
Rolling index builds succeed only when they meet certain conditions. To ensure your index build succeeds, avoid the following design patterns that commonly trigger a restart loop:
Note
Data Explorer doesn’t support building indexes in a rolling fashion for standalone deployments.
Building indexes in a rolling fashion reduces the performance impact of building indexes on replica sets and sharded clusters . To maintain cluster availability, Cloud Manager removes one node from the cluster at a time starting with a secondary .
After you build an index in a rolling fashion, if your MongoDB database
runs with an FCV
less than
4.2
,
resync the head database
to ensure that the head database takes the
new index into account.
Cloud Manager automatically cancels rolling index builds that don’t succeed on all nodes. When a rolling index build completes on some nodes, but fails on others, Cloud Manager cancels the build and removes the index from any nodes that it was successfully built on.
In the event of a rolling index build cancellation, Cloud Manager generates an activity feed event and sends a notification email to the project owner with the following information:
To learn more about rebuilding indexes, see Build Indexes on Replica Sets .
Note
The following index options are incompatible with building indexes in a rolling fashion:
Cloud Manager ignores these options if you specify them in the Options pane.
Important
When an index build completes, Cloud Manager generates an activity feed event and sends a notification email to the project owner with the following information:
This document addresses common questions about Cloud Manager and its use.
On this page
Cloud Manager can automate operations for the MongoDB processes running on your hosts. Cloud Manager can both discover existing processes and deploy new ones.
Cloud Manager Automation relies on an Automation Agent, which must be installed on every server that runs a monitored MongoDB deployment. The Automation Agents periodically poll Cloud Manager to determine the goal configuration, deploy changes as needed, and report deployment status back to Cloud Manager.
Install the MongoDB Agent on each host that you want Cloud Manager to manage. The following procedure applies to all operating systems.
Instructions for a specific operating system can be read on Install MongoDB Agent .
On Linux hosts, if you installed MongoDB with a package manager, use the same package manager to install the MongoDB Agent. If you installed MongoDB without a package manager, use an archive to install the MongoDB Agent.
Once you have installed the MongoDB Agent to all your hosts, you can deploy your first replica set , cluster , or standalone .