【问题标题】:Meteor and GroundDB: find by id not returning any entriesMeteor 和 GroundDB:按 id 查找不返回任何条目
【发布时间】:2020-03-26 19:47:12
【问题描述】:

我正在尝试为我的流星应用程序实现一个离线数据库,并选择使用 “GroundDB”。现在我仍处于早期学习阶段,但我遇到了一个我找不到解决方案的问题:

在我的离线收藏中使用 .find 时,我无法通过 id 找到。其他所有属性都有效。我的 mongo DB 中的一个典型对象如下所示:

{_id:"…someid", name:“test”, description:“test”, systemId:"…someID"};

我可以按名称、描述甚至 systemID 查找,但按 _id 查找总是返回 0 个结果。

什么可能导致这种行为?

这仅适用于 GroundDB。在 mongo 数据库中按 _id 查找有效。此外,GroundDB 中的“_id”字段也在那里!在没有过滤器的情况下执行.find({}) 时,我可以看到所有属性,包括 _id 字段,都被复制到了 groundb。

编辑

我目前关于 groundDB 的代码如下:

ExampleCol = new Mongo.Collection('exampleCol');


if (Meteor.isServer) {
  Meteor.publish('exampleCol', functionexampleColPublication() {
    return ExampleCol.find();
  });
}

在客户端:

ExampleCol_GROUND = new Ground.Collection('exampleCol'
  });
ExampleCol_GROUND.observeSource(ExampleCol.find());

然后: ExampleCol_GROUND.find() 返回所有条目,它们也在 ExampleCol 中。我就是不能ExampleCol_GROUND.find({_id:"..."})(0 个结果)

【问题讨论】:

    标签: mongodb meteor offline-caching findby grounddb


    【解决方案1】:

    所以我找到了一个解决方案,不确定它是否是最优雅的。 GroundDB 似乎正在积极寻找 _id 字段并尝试将其用作选择器。我不确定什么不正确,我想这与我的 _id-field 是一个字符串有关。

    以下作品:

    而不是简单的ExampleCol_GROUND.find({_id:"..."})

    我现在使用“where”语句:

    ExampleCol_GROUND.find({$where: function() {
                       return this._id ==  "..someId.."
                    }});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-13
      • 2014-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-20
      • 1970-01-01
      相关资源
      最近更新 更多