Running a direct command

Often, you simply want to get status information on MongoDB, in which case the database is irrelevant. In this example, we use the --eval flag to run the command db.serverStatus():

In other cases, you might want to run periodic database queries from a cron job. Here is an example where we check for customers in the sweetscomplete database whose balance is 0:

Get MongoDB 4 Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.