Reputation: 9929
How does one print a variable at the MongoDB command prompt. Unbelievably, I cannot figure this out.
Upvotes: 12
Views: 27901
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
Reputation: 18615
> var i = 0;
> i
0
> print(i)
0
>
Use either as appropriate. Happens to the best of us ;)
Upvotes: 23