在 mongodb shell 中打印文档值 [英] Print document value in mongodb shell

查看:45
本文介绍了在 mongodb shell 中打印文档值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 mongo shell 中打印此 JSON 文档的值.就像一个简单的控制台输出,无需创建新的集合或文档.

I want to print the value for this JSON document in the mongo shell. Like a simple console output, without creating a new collection or document.

提前致谢

推荐答案

我找到了一个解决方案,通过使用 .forEach() 来应用一个 JavaScript 方法:

I found a solution, by using .forEach() to apply a JavaScript method:

db.widget.find(
    { id : "4" }, 
    {quality_level: 1, _id:0}
).forEach(function(x) { 
    print(x.quality_level); 
});

这篇关于在 mongodb shell 中打印文档值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆