How do we print a variable at the MongoDB command prompt?

MongoDBDatabaseBig Data Analytics

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!!!
raja
Published on 12-Apr-2019 10:45:14
Advertisements