MongoDB Best Practices¶
Recommendations for getting reliable results and predictable run times from a MongoDB datastore.
Plan the connection¶
Use SRV for Atlas and a member list for a self-hosted replica set. An Atlas address with DNS Seed List (SRV) set to Yes (mongodb+srv, e.g. Atlas) keeps working when Atlas adds or replaces members. For a replica set of your own, list every member with its port in Host. A connection that names a single member stops working as soon as that member is down.
Give Qualytics its own read-only database user. A dedicated user with the read role on the databases you monitor makes it clear in MongoDB's own logs which reads came from Qualytics, and changing its password does not affect your applications. Qualytics never writes to MongoDB through this connector, so read access is all it needs. See Permissions.
Use one connection per deployment and reuse it. Every datastore that reads from the same MongoDB deployment should share one saved connection. The password then lives in one place, so changing it is a single edit rather than one per database. Add further databases with Add with an Existing Connection.
Turn on SSL Connection for any server reached over a shared network. Without it, the password and the documents travel unencrypted between MongoDB and Qualytics. With SRV it is always on.
Get stable fields¶
Run a Sync after the shape of your documents changes. The fields of a collection are worked out at Sync and kept until the next one. A field your application starts writing next week is not profiled or checked until a Sync picks it up, so schedule a Sync after releases that change the documents, or on a regular schedule.
Prefer ObjectId, numeric, or date _id values when you can choose. With those, the sample is drawn from the same documents every time, so a Sync that finds no change in the data gives the same fields. With text or compound _id values, or on time-series collections, the sample is random, and a rare field can appear on one Sync and not the next.
Keep one type per field in your documents. A value whose type does not fit the field the sample settled on reads as empty when it cannot be converted. That shows up as lower completeness in a profile rather than as an error, so mixed types can go unnoticed. Checks such as Not Null on the affected fields make them visible.
Keep operations fast¶
Select only the databases you monitor. Each Sync samples every collection in the database. Creating datastores for databases nobody checks adds that sampling to every Sync without any benefit.
Filter scans on indexed fields. Filters in a scan are passed to MongoDB to narrow what it returns, so a filter on an indexed field lets MongoDB use the index instead of reading the whole collection.
See Also¶
-
Permissions
The access your MongoDB deployment must grant, plus the Qualytics user role and team permission needed to manage the datastore.
-
Authentication
User and password sign-in, the Auth Source database, and when to leave both credentials empty.
-
Examples
Worked scenarios: a MongoDB Atlas cluster, a self-hosted replica set, collections whose documents vary, and several databases at once.