流星:我如何从特定对象的字段中返回数据? [英] Meteor: how do I return data from fields in a specific object?

查看:147
本文介绍了流星:我如何从特定对象的字段中返回数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

myobject 具有各种属性, _id,name,createdBy,date etc

在我的find查询中,我只想从myObject中返回特定的字段。所以,例如,我需要做些什么来修改下面的find查询,以便只返回 name

  myCollection.find({createdBy:someId},{fields:{myObject:1}})。fetch(); 

目前这将返回 myObject 中的所有内容它应该这样做,我只是希望在 myObject 中的一个字段返回。

解决方案

这是在查询中执行的一种方法:


1}})。fetch();



$ b


'myObject.name'



This should be a fairly simple one.

myobject has various properties, _id, name, createdBy, date etc

In my find query I want to only return specific fields from within myObject. So for example, what would I need to do to modify the find query below so that only name was returned?

myCollection.find({createdBy: someId}, {fields: {myObject: 1}}).fetch();

Currently this will return everything in myObject which it should do, I just want one field within myObject returned.

解决方案

Here is a way to do it within the query:

myCollection.find({createdBy: someId}, {fields: {'myObject.name': 1}}).fetch();

Note the quotes around

'myObject.name'

这篇关于流星:我如何从特定对象的字段中返回数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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