
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
How do we print a variable at the MongoDB command prompt?
In order to print a variable at the MongoDB command prompt, use the following syntax
//Declaring and Initializing a variable. var anyVariableName=yourValue; //To print the above variable. yourVariableName; Or print(yourVariableName);
Following is how you can declare and initialize a variable at the MongoDB command prompt
> var myIntegerValue=20;
Print a variable at the MongoDB command prompt:
> myIntegerValue
This will produce the following output
20
You can also use print(). Following is the query
> print(myIntegerValue);
This will produce the following output
20
Let us see another example. Following is the query to declare and initialize a string variable at MongoDB shell.
> var myStringValue="Hello MongoDB!!!";
Following is the query to print a variable at the MongoDB command prompt.
> myStringValue
This will produce the following output
Hello MongoDB!!!
You can also use print(). Following is the query
> print(myStringValue);
This will produce the following output
Hello MongoDB!!!
- Related Articles
- Print structured MySQL SELECT at command prompt
- How can I execute JavaScript at the command prompt?
- How to run a PowerShell script from the command prompt?
- How to run PowerShell commands from the command prompt?
- How do I drop a MongoDB database from the command line?
- How do we initialize a variable in C++?
- Getting MySQL path in command prompt
- How to run a JAR file through command prompt in java?
- How to compile & run a Java program using Command Prompt?\n
- How do we do variable formatting using the tag in HTML?
- How do we declare variable in Python?
- How to install a windows service using windows command prompt in C#?
- How to do Python math at command line?
- How do we access command line arguments in Python?
- How do we set the Java environment variable in cmd.exe?

Advertisements