×

Welcome to Knowledge Base!

KB at your finger tips

This is one stop global knowledge base where you can learn about all the products, solutions and support features.

Categories
All
Database-MongoDB
Avoid Unbounded Arrays — MongoDB Cloud Manager

Avoid Unbounded Arrays¶

On this page

  • Overview
  • Example
  • Learn More

Overview¶

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.

Example¶

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.

Document References May Require $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.

Learn More¶

  • To learn more about Data Modeling in MongoDB and the flexible schema model, see Data Modeling Introduction.
  • To learn how to model relationships with document references, see Model One-to-Many Relationships with Document References
  • To learn how to query arrays in MongoDB, see Query an Array.
  • MongoDB also offers a free MongoDB University Course on Data Modeling: M320: Data Modeling.

MongoDB.live 2020 Presentations¶

To learn how to incorporate the flexible data model into your schema, see the following presentations from MongoDB.live 2020 :

  • Learn about entity relationships in MongoDB and examples of their implementations with Data Modeling with MongoDB.
  • Learn advanced data modeling design patterns you can incorporate into your schema with Advanced Schema Design Patterns.
Configure the Slow Query Threshold — MongoDB Cloud Manager

Configure the Slow Query Threshold¶

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.

Read article
Manage the MongoDB Agent Functions — MongoDB Cloud Manager

Manage the MongoDB Agent Functions¶

On this page

  • Manage Backup Function
    • Activate Backup
    • Deactivate Backup
  • Manage Monitoring Function
    • Activate Monitoring
    • Deactivate Monitoring
  • Manage Automation Function
    • Activate Automation

Manage Backup Function¶

Activate Backup¶

  1. From your Context menu, click the project that has the hosts you want to configure.

  2. Click Deployments .

  3. Click Servers .

  4. On the host where you want to activate Backup, click ellipsis icon .

  5. Click Activate Backup .

  6. From the banner, click Review & Deploy .

  7. 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 .

Deactivate Backup¶

  1. From your Context menu, click the project that has the hosts you want to configure.
  2. Click Deployments .
  3. Click Servers .
  4. On the host where you want to deactivate Backup, click ellipsis icon .
  5. Click Deactivate Backup .
  6. From the banner, click Review & Deploy .
  7. If you want to activate Backup, click Confirm & Deploy . Otherwise click Cancel , then Discard Changes to cancel deactivating Backup.

Manage Monitoring Function¶

Activate Monitoring¶

  1. From your Context menu, click the project that has the hosts you want to configure.

  2. Click Deployments .

  3. Click Servers .

  4. On the host where you want to activate Monitoring, click ellipsis icon .

  5. Click Activate Monitoring .

  6. From the banner, click Review & Deploy .

  7. 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.

Deactivate Monitoring¶

  1. From your Context menu, click the project that has the hosts you want to configure.
  2. Click Deployments .
  3. Click Servers .
  4. On the host where you want to deactivate Monitoring, click ellipsis icon .
  5. Click Deactivate Monitoring .
  6. From the banner, click Review & Deploy .
  7. If you want to deactivate Monitoring, click Confirm & Deploy . Otherwise click Cancel , then Discard Changes to cancel activating Monitoring.

Manage Automation Function¶

Activate Automation¶

Automation is activated when you:

  • Deploy a standalone MongoDB instance
  • Deploy a replica set
  • Deploy a sharded cluster
  • Import an existing MongoDB deployment into Cloud Manager.
Read article
Rotate Automation Password — MongoDB Cloud Manager

Rotate Automation Password¶

On this page

  • Prerequisites
  • Procedure

We recommend that you rotate the automation user’s password periodically. Cloud Manager provides an automated procedure for password rotation with no downtime.

Prerequisites¶

To enable password rotation for the automation user, you must meet the following requirement:

  • SCRAM-SHA-1 or SCRAM-SHA-256 set up as a supported authentication mechanism for the Automation.

Procedure¶

1
2

On the line for the automation user, click Rotate Password

3

Click Review & Deploy to review your changes.¶

4

Click Confirm & Deploy to deploy your changes.¶

Otherwise, click Cancel and you can make additional changes.

Read article
Aggregation Pipeline Builder — MongoDB Cloud Manager

Aggregation Pipeline Builder¶

On this page

  • Required Roles
  • Access the Aggregation Pipeline Builder
  • Create an Aggregation Pipeline
  • Export an Aggregation Pipeline to Driver Language
  • Aggregation Pipeline Settings

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:

  1. Click Deployment in the left navigation.
  2. Select the desired MongoDB deployment.
  3. Select the Data tab.

Required Roles¶

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.

Access the Aggregation Pipeline Builder¶

1

Select the database for the collection.¶

The main panel and Namespaces on the left side list the collections in the database.

2

Select the collection on the left-hand side or in the main panel.¶

The main panel displays the Find , Indexes , and Aggregation views.

3

Select the Aggregation view.¶

When you first open the Aggregation view, the Data Explorer displays an empty aggregation pipeline.

Create an Aggregation Pipeline¶

1

Select an aggregation stage.¶

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.

2

Fill in your aggregation stage.¶

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.

3

Add additional stages to your pipeline as desired.¶

There are two ways to add additional stages to your pipeline:

  • Click the Add Stage button at the bottom of the pipeline to add a new stage at the end of your pipeline:
  • Click the plus icon button on a stage to add a new stage directly after the stage where the button was clicked.
Screenshot highlighting add stage button.

To delete a pipeline stage, click the trash icon icon on the desired stage.

4

Repeat steps 1 and 2 for each additional stage.¶

Collation¶

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.

Import an Aggregation Pipeline from Text¶

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:

1

Open the New Pipeline from Text dialog.¶

  1. Click the arrow next to the plus icon at the top of the pipeline builder.

  2. Click New Pipeline from Text .

2

Type or paste your pipeline in the dialog.¶

Your pipeline must match the syntax of the pipeline parameter of the db.collection.aggregate() method.

3

Click Create New

4

Click Confirm in the ensuing dialog.¶

Reset Your Pipeline¶

To return your pipeline to the initial blank state, click the plus icon at the top of the pipeline builder.

Export an Aggregation Pipeline to Driver Language¶

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:

1

Construct an aggregation pipeline.¶

For instructions on creating an aggregation pipeline, see Create an Aggregation Pipeline .

2

Click Export to Language at the top of the pipeline builder.¶

3

Select your desired export language.¶

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.

4

Include import statements, if desired.¶

(Optional) : Check the Include Import Statements option to include the required import statements for the language selected.

5

Click the Copy button.¶

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.

6

Click Close to return to the aggregation pipeline builder.¶

Aggregation Pipeline Settings¶

To modify the aggregation pipeline builder settings:

1

Click the settings icon icon at the top-right of the pipeline builder.¶

Screenshot highlighting pipeline settings button.
2

Modify pipeline settings as desired.¶

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
3

Click Apply to save your changes.¶

Read article
MongoDB Agent — MongoDB Cloud Manager

MongoDB Agent¶

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.

  • Activate the monitoring and/or backup functions using Cloud Manager UI.
  • Activate automation when you create a new cluster or import an existing one.
MongoDB Agent Prerequisites
Configure MongoDB Agent prerequisites.
Install MongoDB Agent
Install the MongoDB Agent.
Update to the MongoDB Agent
Update the MongoDB Agent.
Restart the MongoDB Agent
Restart the MongoDB Agent.
Manage the MongoDB Agent Functions
Activate or deactivate all functions of the MongoDB Agent.
MongoDB Agent Settings
Find all possible settings available in the MongoDB Agent configuration file.
Required Access for MongoDB Agent
Details the permissions required for MongoDB Agent to use with MongoDB instances that enforce access control.
Configure the MongoDB Agent for Access Control
If MongoDB uses Access Control, create a MongoDB user for the MongoDB Agent to use to authenticate and to determine the Agent’s access.
Configure MongoDB Agent to Use TLS
Configure the MongoDB Agent for TLS.
Configure How the MongoDB Agent Manages Config Files and Passwords
Configure how the MongoDB Agent stores its configuration and manages its passwords.
Remove Legacy Agents
Remove the legacy Backup and Monitoring Agents.
View Agent Status
View the status of a project’s agents.
Manage Agent API Keys
Manage project’s agent API keys.
Read article

Still Thinking?
Give us a try!

We embrace agility in everything we do.
Our onboarding process is both simple and meaningful.
We can't wait to welcome you on AiDOOS!