【问题标题】:Reading mongo collection created outside of meteor阅读在流星之外创建的 mongo 集合
【发布时间】:2015-01-28 22:46:49
【问题描述】:

我有一个在 Meteor 之外创建的 mongo 集合,其中包含想要访问我的应用程序的人的用户信息。在 MongoVue 中是这样的-

**tmpUsers**

/* 5 */
{
 "_id" : ObjectId("54c7ae456587e23335915948"),
 "email" : "trial@domain.com",
 "first" : "Trial User",
 "type" : "trial",
 "active" : "Yes"
}

当我尝试阅读这篇文章时,我基本上得到了一个像这样结构的空集合 -

collection: 
 d_docs: d._IdMap_..........

这是我的代码 -

**client**

    var type = "";
    var tmpCursor = tmpUsers.find({"email": Meteor.user().emails[0].address});
    tmpCursor.forEach(function(rec) {
        type = rec.type
    });
    Meteor.call("updateProfile", Meteor.userId(), type);

**server**

    Meteor.methods({
    "updateProfile": function(id, value){
        Meteor.users.update({"_id": id}, {$set: {"profile.acctType": value}});
    }
   })

如何更新客户端代码以从 tmpUsers 读取类型?

更新:

这是我从 Meteor 外部插入记录的地方 -

        try {
        $mongoDb = $mongoConn->abcdefg;
        $collection = $mongoDb->tmpUsers;
        $userInfo = array("email" => $_POST['email'],  'first' => $first,"type" => $_POST['type'], 'active' => $activation);
        $collection->insert($userInfo);
    } catch (MongoException $e) {
        die('Error: ' . $e->getMessage());
    }

【问题讨论】:

    标签: mongodb meteor


    【解决方案1】:

    试试这个。

    Tracker.autorun(function(){ 
       Meteor.subscribe('tmpUsers',function(){ 
        var finde = tmpUsers.find({email:Meteor.user().emails[0].address}).count(); 
      if (finde === 1){ 
          console.log("found email"); 
       } else{ 
         console.log("not email found") 
        } 
     }); 
    });
    

    【讨论】:

    • 不确定我是否遵循这个。该数据库仅在我为 tmpUsers 插入记录的位置外部。我尝试阅读 type = rec.type 的地方是我无法从 tmpUsers 获取类型的地方。
    • 所以 tmpUsers,外部数据库是吗?
    • 是的,但仅限于 php 端的外部。 Meteor 发布和订阅它。
    • 如果您在控制台上运行查找,它是否有效?你确定连接完成了吗?
    • 从控制台查找可以工作,但不会像其他查找那样映射字段名称。使用 MongoVue,我可以看到 PHP 在数据库中获取它们,但我认为这种格式会导致查找为空 "_id" : ObjectId("54c7ae456587e23335915948"),但是如果我使用 PHP 端函数创建一个随机的 17 个字符 id,则查找仍然没有返回任何内容。从控制台返回与 tmpUsers 中的值匹配的电子邮件地址 - Meteor.user().emails[0].address
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-11
    • 1970-01-01
    • 2016-08-28
    • 2013-01-02
    • 1970-01-01
    • 2016-05-15
    • 1970-01-01
    相关资源
    最近更新 更多