
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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!!!
Advertisements