首页 \ 问答 \ Meteor集合find()方法即使已订阅也未定义(Meteor collection find() method is undefined even though its subscribed)

Meteor集合find()方法即使已订阅也未定义(Meteor collection find() method is undefined even though its subscribed)

我正在尝试实现一个照片查看器应用程序,它将图像URL和它所属的用户ID存储在一个集合中。 当我尝试Collection.findOne时,它总是返回null。

var name = Meteor.user().username;
var message = $('.action-textarea').val();
var userId = Meteor.userId();
var file = $("#input-photo").get(0).files[0];
if(file) {
    fsFile = new FS.File(file);
    var id = PostGeneralImages.insert(fsFile, function(err, result) { 
        if(err) {
            throw new Meteor.Error(err);
        } else { 
            var imageLoc = '/cfs/files/PostImages/' + result._id;
            PostImages.insert({
                    generalId: result._id,
                    userId: Meteor.userId(),
                    username: Meteor.user().username,
                    imageLoc: imageLoc
                });       
            }
        });
    }
var imagePath = PostImages.findOne({generalId: id._id}).imageLoc;
console.log(imagePath);

在控制台上未定义imagePath。 但是当我在控制台中尝试findOne方法时,它成功返回了想要的对象。 我已经发布并订阅了该系列。


I'm trying to implement a photo viewer app that stores image url and it's belonging user id in a collection. When I try to Collection.findOne that value it always returns null.

var name = Meteor.user().username;
var message = $('.action-textarea').val();
var userId = Meteor.userId();
var file = $("#input-photo").get(0).files[0];
if(file) {
    fsFile = new FS.File(file);
    var id = PostGeneralImages.insert(fsFile, function(err, result) { 
        if(err) {
            throw new Meteor.Error(err);
        } else { 
            var imageLoc = '/cfs/files/PostImages/' + result._id;
            PostImages.insert({
                    generalId: result._id,
                    userId: Meteor.userId(),
                    username: Meteor.user().username,
                    imageLoc: imageLoc
                });       
            }
        });
    }
var imagePath = PostImages.findOne({generalId: id._id}).imageLoc;
console.log(imagePath);

imagePath is undefined on console. But when I try findOne method in console it successfully returns the wanted object. I'm already publishing and subscribing that collection.


原文:https://stackoverflow.com/questions/35514324
更新时间:2022-06-10 11:06

最满意答案

假设您的表按日期排序(它在图片中),那么可以使用VLOOKUP解决第一个问题

=VLOOKUP("1",A1:C6,3,0)

"1"替换为新表中包含ID 1单元格。

对于问题2,您可以使用以下公式,再次使用新表中包含ID 1单元格替换=1

{=MEDIAN(IF(A1:A6=1,C1:C6,""))}

注意,这是一个数组公式,你不直接键入大括号{} ,但只需按CTRL + SHIFT + ENTER ,而不是输入公式时只需输入

这可以通过创建像这样的数组{12,23,"","",""}并取这些数字的中位数来实现。 MEDIAN忽略字符串,因此根据需要给出中间值12和23(ID 1的示例)


Assuming your table is ordered by date (which it is in the picture), then the first question can be solved using a VLOOKUP

=VLOOKUP("1",A1:C6,3,0)

Replace "1" which whichever cell contains the ID 1 in your new table.

For question 2, you can use the following formula, again replacing =1 with whichever cell contains ID 1 in your new table

{=MEDIAN(IF(A1:A6=1,C1:C6,""))}

Note, this is an array formula, you don't type the curly brackets {} directly, but simple press CTRL+SHIFT+ENTER, rather than just ENTER when entering the formula

This works by creating an array like this {12,23,"","",""} and taking the median of those numbers. MEDIAN ignores the strings so gives you the median of 12 and 23, as required (example for ID 1)

相关问答

更多
  • 我认为这可能适合你。 首先,这是我如何定义我的测试表和测试数据: declare @stock table ( transId int not null identity(1,1), [date] date not null, -- use datetime if not using SQL Server 2008 input decimal(7,2) null, [output] decimal(7,2) null ); insert into @stock values ('1/2 ...
  • 至少有一个问题是.keyup()方法需要一个函数。 在您的示例中使用calculate的方式,您在添加事件时立即调用该函数。 为避免这种情况,您可以执行以下操作: $('#p1').keyup(function () { calculate('#p1') }); 另一种选择是让calculate函数返回一个函数引用: function calculate(input) { return function () { $(input + 'Total').val($(input).va ...
  • 插件作者在这里。 我在http://c17r.github.io/jAutoCalc/sample更新了示例,以包含动态添加/删除行。 整个事件以一种树状结构运行场外事件; 当事情发生变化时,它会有点偏离轨道。 最简单的方法是包装你的代码,将jAutoCalc连接到它自己的函数中 function autoCalcSetup() { $('form[name=cart]').jAutoCalc('destroy'); $('form[name=cart] tr[name=line_items ...
  • 我在编程中学到的第一件事就是当你不知道如何编写代码时,首先写出你自己用来解决它的过程(算法),一步一步,然后看看如何翻译那要编码。 听起来像是一个很好的第一步,你可以写出如何在纸上解决问题 - 而不用担心分区问题。 我知道你的问题不是微不足道的,但我会用一个求和的例子。 要查找所有记录的总数,您需要记录0 +记录1 +记录2 + ... +记录2499 =总和。 有了这个,你可以去看看它是否可以分区。 另外,这很容易做到,因为加法是关联的。 分组操作,这是一个分区。 现在,如果您无法找到手动分区计算的方法, ...
  • 好的,在biziclops提示的帮助下,我找到了CASE语法,现在得到了一个解决方案: SELECT wt.begin, wt.end, CASE WHEN strftime('%w', wt.begin)='1' THEN Mon WHEN strftime('%w', wt.begin)='2' THEN Tue WHEN strftime('%w', wt.begin)='3' THEN Wed WHEN strftime('%w', wt.begin)='4' THE ...
  • SELECT PDate, ItemName, MPQty, PQty, ISNULL(SQty,0) AS SQty, ISNULL((CASE WHEN SQTY>=PQty THEN 0 WHEN (SQty+MPQty)>PQty THEN PQty-SQty ELSE MPQty END),0) AS Qty, Rate, (ISNULL((CASE WHEN SQTY>=PQty THEN 0 WHEN (SQty+MPQty)>PQty THEN PQty-SQty ELSE MPQty EN ...
  • 根据你的jsfiddle,你没有在表#quandatbl中输入。 尝试更改功能 function calculateTotal() { var totalweight = totalmarks; $("#qandatbl_onthefly_container td.weight input").each(function (i, elm){ totalweight = totalweight - Number($(elm).val(), 10); }); $(" ...
  • 假设您的表按日期排序(它在图片中),那么可以使用VLOOKUP解决第一个问题 =VLOOKUP("1",A1:C6,3,0) 将"1"替换为新表中包含ID 1单元格。 对于问题2,您可以使用以下公式,再次使用新表中包含ID 1单元格替换=1 {=MEDIAN(IF(A1:A6=1,C1:C6,""))} 注意,这是一个数组公式,你不直接键入大括号{} ,但只需按CTRL + SHIFT + ENTER ,而不是输入公式时只需输入 这可以通过创建像这样的数组{12,23,"","",""}并取这些数字的中 ...
  • 这是基础R中相当简单的方法。 with(df, cumsum(x + ifelse(is.na(ed0), 0, ed0) + c(0, head(kd, -1)))) [1] 0.2432977 30.2080240 70.1648789 为了解决这个问题,x保持原样并且c(0, head(kd, -1))设置kd的滞后向量,其中初始值为0. ifelse(is.na(ed0), 0, ed0)检查如果ed0的每个元素都是NA,如果为TRUE则将其替换为0。 将这三个术语相加在一起,并将得到的矢量给予 ...
  • 你不能在计算时使用别名 select invoice_ no, exe_amount, exe_amount*0.02 as edu_duty, exe_amount*0.01 as ed_duty, (exe_amount + (exe_amount*0.02) + (exe_amount*0.01)) as sub_total, ((exe_amount + (exe_amount*0.02) + (exe_amount*0.0 ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)