cammil
cammil

Reputation: 9929

How does one print a variable at the MongoDB command prompt?

How does one print a variable at the MongoDB command prompt. Unbelievably, I cannot figure this out.

Upvotes: 12

Views: 27901

Answers (2)

SaM
SaM

Reputation: 31

You can execute Java Script in Mongo CLI or command prompt The print() method simply prints the data arguments that are passed into it. print("Hello From Mongo");

eg:

print(data, ...);
printjson(object);
print(JSON.stringify(object));

The printjson() method prints a pretty form of the JavaScript object. The print(JSON.stringify(object)) method also prints a tightly compact string form of a JavaScript object.

Upvotes: 3

Remon van Vliet
Remon van Vliet

Reputation: 18615

> var i = 0;
> i
0
> print(i)
0
>

Use either as appropriate. Happens to the best of us ;)

Upvotes: 23

Related Questions