When print() seems broken in the MongoDB shell, the fix is almost always environmental rather than a MongoDB failure: output is being swallowed by a wrapper, redirected to a file, buffered in a pipe, or written somewhere your terminal isn't showing. Test with mongosh --nodb and a one-line print("hello") first; if that works, the shell is fine and the problem is in how you launched it or where its output went. This guide covers the realistic ways print output disappears and gives you ordered checks to bring it back without guessing.
The term "mongo print" covers a few different things, and it's worth naming them before touching any commands. People usually mean one of:
The legacy mongo shell (the old mongo binary, print() is a built-in helper from the shell's JavaScript runtime). MongoDB deprecated the legacy shell and it's been removed from current distributions, so if you're running a recent server, the old mongo command may simply not exist. mongosh (the current MongoDB Shell), which also exposes a print() helper in its JavaScript environment and additionally provides console.log(). A driver script or application (Node.js, Python, Java) where "print" means whatever output function that language provides, and the problem is logging configuration rather than the MongoDB shell. The print output of a query, that is, the formatted result of db.collection.find(), which in some contexts is called "printing a document."
The fixes differ depending on which of those you're dealing with, so the first job is diagnosis. From here, the steps are ordered so that each one is cheap and reversible, and each one is a real test, not a guess.
First: determine which "mongo" you actually have
Run mongo --version and mongosh --version from the same terminal where the problem occurs. Three outcomes matter.
If mongosh --version responds with a version number, you have the current shell installed. If mongo --version fails with "command not found," you're on a system where the legacy shell is absent, which is normal for current MongoDB installs. If both work, you may have both installed and are launching the wrong one; scripts written for the legacy shell's helper functions may not behave identically in mongosh.
This matters because print() exists in both shells, but the surrounding behavior does not. In the legacy shell, several helper functions from the old mongo script ecosystem existed by default; in mongosh, some of those were replaced or moved, and output handling (including what gets echoed) is different. If a tutorial written around 2016 tells you to type mongo and you're following it in 2026, the first thing to verify is whether your environment even has that command.
The other reason to start here is simple: if you're connected to a server through a tool that wraps the shell (an IDE console, a GUI client's embedded shell, a Docker exec command), the shell may be fine and the wrapper may be hiding output. Testing with --nodb isolates the shell from both the server and any connection configuration.
Isolate the shell with a no-database test
This is the single most useful check. In a terminal, run:
--nodb starts the shell without connecting to any server. --quiet suppresses the startup banner. --eval runs a single expression and exits. If "hello from mongosh" appears in your terminal, then print works in the shell itself, and the problem is in connection setup, script context, wrapper tooling, or output redirection. If nothing appears, or only the banner appears, the shell or the terminal is eating the output.
Note one detail: print() in mongosh writes to standard output, and a trailing semicolon inside --eval is fine. If you're on Windows, the quoting rules differ; single quotes around the eval string behave differently in cmd.exe than in PowerShell or a POSIX shell. If the command returns a syntax error, that's a quoting problem, not a print problem, and it's worth checking before concluding the shell is broken.
A related variant tests console.log:
If console.log works but print doesn't under identical conditions, you're likely in a driver context where print was never defined, or you're in mongosh with something overriding the global print. If the reverse is true, you have a more unusual environment, possibly a sandboxed embedded shell.
Check whether your output is being redirected
The most common reason "the print is gone" after working for a while is that output went somewhere other than the visible terminal. Systematic checks:
1: Command-line redirection. If your command was mongosh --eval 'print("x")' > out.txt, the output is in out.txt, not on screen. Try cat out.txt. If the file is empty while the command succeeds, the output went to standard error instead, and you'd need 2> to capture it, or 2>&1 to combine both streams. 2: Piped output. In mongosh ... | grep something, the output is consumed by the next command. If the pattern doesn't match, you see nothing. Remove the pipe and run again to see the raw output. 3: Shell inside a Docker container. docker exec without -it can behave oddly with interactive shells, and stdout may be attached to a different stream than you expect. Running the eval form with -i attached, or capturing with docker exec ... mongosh ... 2>&1, tells you which stream is carrying the text. 4: Wrapper scripts and aliases. An alias like mongo='mongo --quiet 2>/dev/null' will silently drop stderr. Check with alias and type mongo (or type mongosh) in the same shell. 5: Output sent to a file by the application. If a cron job or script redirects, the "missing" output exists on disk. Search recent files in the working directory before changing anything.
A subtle case: some environments buffer output and only flush it when the process exits or the buffer fills. A short script that prints and then keeps running may appear to print nothing until it terminates. If that matches your symptom, the fix is to force a flush or eliminate buffering at the calling level, not to change the print call itself.
Confirm the script context and variable scope
If print("hello") works interactively but not in your script, the problem is usually that the code never reaches the print, or it runs in a context where print isn't defined.
For mongosh, a script run with --file executes in the shell's JavaScript environment, so print should be available. Two things commonly break this:
An error stops execution before the print. JavaScript runs statements in order. If a query throws, the next line never runs. Wrap the troublesome part in try { ... } catch (e) { print("failed: " + e); } to see whether execution reached it. The script runs in a different context than you think. If your code is passed through a driver or an IDE runner, print may not be a global. In a Node.js driver script, print is not defined at all; you use console.log(). In the mongosh environment, print is defined, but code executed inside some wrappers may be evaluated in a sandbox where it isn't. Test by adding console.log(typeof print) right before the line you expect to output; the result tells you whether the function exists in that scope.
For cursors, one more context issue is worth knowing. In mongosh, db.collection.find() returns a cursor. Simply evaluating it at the prompt prints a batch of documents, but in a script, you need to iterate it: db.collection.find().forEach(d => printjson(d)), or in the current shell syntax, iterate with a for loop over await when using mongosh's async iteration. If you call print on the cursor object itself, you'll get something like [object Object] or a cursor description rather than the documents. That's not a broken print; that's printing the wrong thing.
Restore collection-level printing with forEach and printjson
If your goal is to see query results as text, the canonical pattern has been stable across shell generations:
Legacy shell: db.users.find().forEach(function(doc) { printjson(doc); }); mongosh: db.users.find().forEach(doc => printjson(doc)); also works, and printjson is available in both. If you need plain JSON rather than the extended format, print(EJSON.stringify(doc)) gives you a string with types represented explicitly.
Why printjson and not print? print on an object converts it to a string, which for documents gives you [object Object] rather than the fields. printjson formats the document properly. If you formerly used a one-liner that "printed the documents" and now it prints [object Object], the fix is to switch to printjson or to explicitly stringify.
A related trap is that large result sets get truncated to a default batch. Cursors print a limited number of documents before requiring it (legacy) or continuing iteration. If your output "stops" after a handful of results, that's batching, not a lost print. Use forEach to process every document without interactive pagination.
Fix driver-side printing (Node.js, Python, and similar)
If "mongo print" means printing to the console from an application using the MongoDB driver, the shell tips don't apply. The mechanism is language logging:
Node.js driver: console.log() writes to stdout; console.error() writes to stderr. If your logs disappear in a test runner, the runner may be capturing stdout; check its reporter settings. If you're in an async function, make sure the print occurs after await on the query; otherwise you print an unresolved promise, which looks like Promise { } or just a promise object. Python (PyMongo): use print(...). A common mistake is printing a cursor object before iterating it; print(collection.find()) shows a cursor, not documents. Convert with list(collection.find()) or iterate with for doc in collection.find(): print(doc). If output vanishes under a process manager or a notebook, check whether the environment captures stdout and only flushes on cell completion.
The general diagnostic is the same as in the shell: print a fixed string first, confirm it appears, then print the query result. The gap between those two results localizes the problem fast.
A worked example of the diagnostic order
Suppose you're following an older tutorial and type mongo, get no print output, and conclude the shell is broken. In order:
1: mongo --version fails: the legacy shell isn't installed. That alone explains it, and nothing is broken. Use mongosh instead. 2: mongosh --nodb --quiet --eval 'print("ok")' prints ok. The shell and terminal are fine. 3: In an interactive session, print(typeof print) returns function. The helper is present. 4: db.test.insertOne({a: 1}) then db.test.find().forEach(d => printjson(d)) prints the document. Query printing works. 5: Your script still shows nothing: add console.log("reached line 1") before the query. If that appears but the print after the query doesn't, the query threw. The try/catch from earlier surfaces the error.
At no point did this require changing MongoDB's behavior; each step shrank the unexplained zone until the actual cause was visible.
When it's actually a server-side or configuration issue
Rarely, output looks absent because your connection never reaches the server, or because a setting suppresses echo. Two checks:
Run db.runCommand({ ping: 1 }) to confirm connectivity; a failed ping means your prints may be failing silently because the session died earlier than you thought. If you use a read preference or a replica set configuration, a query might return an empty result where you expect documents; in that case print works and prints nothing because the cursor is empty. Confirming with db.collection.countDocuments({}) distinguishes empty data from missing output.
If you're working on a genuinely critical production system and output loss is tied to operational tooling you don't control, the practical stop condition is this: once you've confirmed the shell prints in isolation and the problem remains inside your application's deployment environment, involve whoever owns that environment's logging pipeline. Guessing at logstash, container logging drivers, or orchestration configuration from the outside wastes time, and those configurations deserve a proper audit by the people responsible for them.
The broader point is that print has never had a single behavior across all MongoDB contexts, and the shell's migration from mongo to mongosh changed the environment around it more than it changed the helper itself. Treating "print is broken" as "the helper was removed" sends you down the wrong path; the helper is trivial and almost always present. The variables that actually change are the binary you launched, the stream your terminal shows, and the code path that reaches the print call. Testing a literal string first, then the variable, then the query, keeps the diagnosis honest and quick.