How does one print a variable at the MongoDB command prompt?
How does one print a variable at t开发者_StackOverflow中文版he MongoDB command prompt. Unbelievably, I cannot figure this out.
> var i = 0;
> i
0
> print(i)
0
>
Use either as appropriate. Happens to the best of us ;)
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.
精彩评论