流星-collection.find()始终返回所有字段 [英] Meteor - collection.find() always returns all fields

查看:69
本文介绍了流星-collection.find()始终返回所有字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遇到这个问题(有点烦人),我试图查找集合中的所有记录,而不显示(或显示)特定字段(得分).这只是一个示例,并不能反映我的实际代码,但是该问题始终可以重现.我要排除的字段非常大,我只是想生成一个包含可用记录的菜单.

Ran into this (slightly annoying problem) I'm trying to look up all records in a collection and not show (or show) a specific field (score). This is just an example and not reflective of my actual code, but the problem is always reproducible. The fields I am excluding are very large and I'm merely trying to generate a menu of available records.

类似

    players.find({},{score:1})
    players.find({},{score:0})

始终返回每个字段,而不是触发mongodb中的排除/包含.我不需要担心什么,因为模板可以控制哪些数据呈现为html?仍然感觉无论如何数据都已传输到客户端.并显示在控制台中.

Always return every field, instead of triggering the exclude/include in mongodb. Am I worried about nothing, since the template potentially can control what data gets rendered to html? Still feels like the data is transferred to the client side regardless; and shows up in the console.

推荐答案

您的语法有些偏离,应该是

your syntax is off a bit, it should be

CollectionName.find({}, {fields: {'onlyThisField':1}});

CollectionName.find({}, {fields: {'everythingButThisField':0}});

您的模板确实控制了显示哪些数据,但是在许多情况下,限制字段有意义-数据的保密性或效率(所有记录的某些字段,当前"记录的所有字段)是两个常见的情况

your template does indeed control what data is displayed, but there are still many scenarios where field limiting makes sense - privacy of data or efficiency (some fields of all records, all fields of the 'current' record) are two common ones

您没有提及它,但这通常在发布功能中-请参见 http://docs.meteor.com/#meteor_publish -客户端上也可以使用fields修饰符,但它并不限制发送给客户端的数据,仅限于模板-服务器端字段的减少/选择具有不同的优点

you didnt mention it, but this usually is within a publish function - see http://docs.meteor.com/#meteor_publish - the fields modifier is also available on the client, but there it does not limit data sent down to client, just to the template - server side field reduction/selection has different benefits

-

再次检查您是否也删除了autopublish软件包,但是,如果您具有该激活状态并编写自己的发布函数,则应该看到一条警告,这是您最常使用的fields

double check that you've removed the autopublish package too, however you should see a warning if you have that active and write your own publish functions, which is where you would most commonly use fields

这篇关于流星-collection.find()始终返回所有字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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