Meteor and GroundDB: find by id not returning any entries

90 views Asked by At

I am trying to implement an offline DB for my meteor app and chose to use “GroundDB”. Now I am still in my early learning phases but I am having a problem for which I cannot find a solution:

when using .find on my offline-collections, I cannot find by id. Every other property works. A typical object from my mongo DB will look like this:

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

I can find by name, description and even systemID, but finding by _id is always giving back 0 results.

What could cause this behaviour?

This is only for GroundDB. Finding by _id in mongo database works. Also, the “_id” field in GroundDB is there! When doing a .find({}) without filters, I can see that all properties, including the _id-field, get copied to groundb.

Edit

My current code regarding groundDB looks as follows:

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


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

On Client:

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

And then: ExampleCol_GROUND.find() returns all entries, that are also in ExampleCol. I just cannot ExampleCol_GROUND.find({_id:"..."}) (0 results)

1

There are 1 answers

0
CaptainSaftig On BEST ANSWER

So I found a solution, not sure if it is the most elegant. GroundDB seems to be actively looking for an _id field and trying to use that as a selector. I am not sure what is not working exactly, i guess it has something to do with my _id-field being a string.

Following works though:

instead of a simple ExampleCol_GROUND.find({_id:"..."})

i use a 'where' statement now:

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