DB updates not persisting only when client viewing certain pages in app


I have a bit of a strange issue that I can’t seem to get my head around…

I am trying to update a doc, but when I have a client open and subscribed to that collection, the update succeeds (either from method call or from mongo shell - no errors) but the data change doesn’t persist.

If I browse to another page in the app and try the update from the shell again, the change does persist.

I thought it might be schema related, but the only schema I have set for that collection is on a different method. Just in case that was causing weird issues, I commented out anything to do with that method and restarted the app… Issue still happening…

Is there something with Simpl-schema that persists even between app restarts? And is a simpl-schema attached to a single method then applied all the time for that collection?

Any ideas welcome!


Ok a little more info. It would appear that only certain updates hit the issue:

Non working example

db.jobRoles.update({ _id: “TEuffsddARMe4FFNo” }, { $push: { “stages.columns.Invited”: { “test”: “test” } } })

Working example

db.jobRoles.update({ _id: “TEuffsddARMe4FFNo” }, { $push: { candidates: { “test”: “test” } } })

So is it something to do with a deeply nest document ID perhaps?

It looks like you’re doing thing on the client side (minimongo) only.

The mongo shell is server side though no?

Maybe you could provide some more info to your data structure. What schema does your jobRoles collection have?

No Schema applied directly to the collection at the moment.

The only schema involvement is used in a validated-method, which does update the same collection, but is not the method I’m calling.

The only other collection configuration in play is a collection hook before insert to add createdAt

A schema is the structure of your collection and determines what is a string, a boolean, an object, an array and so on.

You always have a schema - in your case it’s implicitly defined by what you insert into the collection. That’s why your query fails: You’re running afoul of your implicit schema.

(Granted: With NoSQL databases it’s perfectly possible to have ambiguous or chaotic schemata - but in that case you’re probably a fool and deserve all the pain this brings :wink: That’s actually one of the advantages of SQL databases: They may not be as flexible but at least you always know what’s what)

Ok in that case why do all other updates work?

And why does this one work when I’m not connected via certain clients?

I don’t know because I don’t know the structure of the collection you’re updating against.

Here, this would be an exemplary instance of a schema:

data: "foo",
example_array: [
   {name: 'bar', 
    tel: 0123,
    friends: [
        { id: "baz" },
        { id: "foobar" }

Without that, we cannot help you

Ok here’s an example document with relevant info included:

    "_id" : "TEuffsddARMe4FFNo", 
    "name" : "foo", 
    "stages" : {
        "columns" : {
            "Invited" : [
                    "candidateId" : "jrBRp4Kw2gvj7twtd", 
                    "firstName" : "foo", 
                    "lastName" : "bar", 
                    "email" : "foo@bar.com", 
            "Stage 2" : [], 
            "Stage 3" : [], 
            "Stage 4" : [], 
            "Stage 5" : []
        "ordered" : []
    "createdAt" : 1536524220399.0


Okay, that’s weird. What does your publish function look like?

Also, if you change the value through meteor mongo what does the document look like immediately after the change when you query it through mongo shell?

I’m not too worried about the publish because it’s not updating on the backend.

If I change the value through meteor mongo and then query it through mongo shell it is not there, even though I get:

meteor:PRIMARY> db.jobRoles.update({ _id: "TEuffsddARMe4FFNo" }, { $push: { "stages.columns.Invited": { "xxxxxxxxxxxxxxx": "xxxxxxxxxxxxxxx" } } })
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

But - If I browse to a different page on the app and do the exact same command, it does update on the backend updating through the shell.

So something about a client being on a specific page on the client is seemingly causing a weird backend issue. So maybe it is pub/sub related I don’t know.

If I run an update to a different field of the same document it works perfectly. For example:

meteor:PRIMARY> db.jobRoles.update({ _id: "TEuffsddARMe4FFNo" }, { $push: { candidates: { "xxxxxxxxxxxx": "xxxxxxxxxxxx" } } })
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

(This candidates array isn’t shown in the example schema I showed you but it does exist. I just trimmed stuff out).

And you’re sure you’re not doing weird stuff inside the publication? Because when you’re on a different page, you unsubscribe to the publication.

It’s used on a couple of pages so a little complex. But I’ve commented where I’d return for the pages I see and don’t see the issue.

Meteor.publish('roles', function (org, role, archived) {
  if (this.userId) {
    const user = Meteor.users.findOne(this.userId);
    if (user.org === org) {
      if (role) { // This is the page I have the issue
        return JobRoleItems.find({ $and: [{ org }, { _id: role }] });
      } else if (archived === true) { // Here or..
        return JobRoleItems.find({ org }, { fields: { stages: 0 } });
      } return JobRoleItems.find({ org, archived: false }, { fields: { stages: 0 } }); // ...Here it works absolutely fine
    } return JobRoleItems.find({}, { fields: { assessments: 1, interviews: 1, name: 1, jobDesc: 1 } });

Does this query work if you execute it manually?

And you don’t have any side-effects going on anywhere else?

It does yeah and no, no other side effects I’ve come across.

have you removed the insecure package?

Yes insecure package is removed.

This has the feeling of a bug to me (although I don’t know enough to say for definite), just because it’s a very specific thing that is failing. When connected to a specific page, updates to an entry level array work fine, but updates to a nested array do not. The same updates work fine when not connected to that specific page so the update syntax is fine.

Is there anyone from MDG that might be able to help? Is there a way to flag or report these types of things?

Ok here’s where it gets even crazier. The broken page has tabbed views (controlled through react state). When viewing a different tab (same page route, subscriptions etc), I can do the update on the backend.

How the hell react state is dictating DB calls I have no idea. Now I’m well and truly stumped :smiley:

You can report it on Github. But for that you’ll also need to provide a repository through which one can easily reproduce the issue.