获取文档的特定部分 [英] Get specific part of document

查看:40
本文介绍了获取文档的特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试Mongo数据库,我想知道是否只能获取文档的特定部分?

I'm trying Mongo db and I wonder if it's possible to only get a specific part of a document?

例如我有:

{
  "name" : "MongoDB",
  "info" : { x : 203, y : 102 }
}

,我只想要info的内容.

我找到的最接近的是db.collection.find({}, { info: 1 }),但是当我只需要{ x : 203, y : 102 }时,它将返回我{ "info" : { x : 203, y : 102 } }.

The closest I found is db.collection.find({}, { info: 1 }) but this returns me { "info" : { x : 203, y : 102 } } when I only need { x : 203, y : 102 }.

推荐答案

您可以做到

db.collection.find({},{'info.x':1, 'info.y':1})

但这意味着在投影中列出信息对象的每一项-可能不是您要找的内容.

but that means listing each and every item of the info object in the projection - which may or may not be what you're looking for.

这篇关于获取文档的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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