Does Meteor Not Supporting Reactive Database Views On The Latest Version?

Hello Guys,

Previously our meteor app working fine so far on 1.6+ we don’t have any issues with our database structure but with the latest updates we observed that the views type of collections takes to 3-10 minutes before it refreshed the data on client side.

Here’s the picture of some of our views collections.
Capture

And here’s how we published that on server side.

Meteor.publish("Jobs_relations", function (params, _clr) {
    
    this.unblock();
    
    if(params){
        const _qV = Jobs_relations.find(params, ((_clr) ? _clr : {}));
        return _qV;
    }
});

And here’s our subscription

Template.jobViewTemplate.onCreated(function(){
   this.autorun(() => {
       _subsc_Jobs_relations = Meteor.subscribe('Jobs_relations', {_number : Number(_route.params._id)});
   });
});

With that approach we didn’t encountered any issue so far on 1.6+ version but on the latest version @ 1.7 it doesn’t working anymore… The data on client changed if I reload the page. :frowning: :frowning: :frowning:

Is there any reason why it happens? And some suggestion on how to fixed it?


UPDATE

Ok, I’ve found the specific issue. The issue is on subscription it doesn’t update the data on client side with the fresh data rendered by publication.

(Still investigating…)


UPDATE

It’s now fixed by upgrading the node version to v8.9.1

Do you have any errors logged in the client console?

Could _route.params._id ever not be initialized?

stick some logging statements into the publish function to see what is up.

Maybe try this:

Meteor.publish("Jobs_relations", function (params, _clr) {
    
    this.unblock();
    
    if(params && params._number){
        const _qV = Jobs_relations.find(params, ((_clr) ? _clr : {}));
        return _qV;
    } else this.ready()
});

Remember, until you get a valid query in the publication it is not reactive. So when your initial if(params... does not pass, the Meteor.publish is not reactive.

If _route.params._id is possibly changing then on client side, you will want a reactive variable for _route.params._id so that the autorun will get executed on changes to _route.params._id.

No errors on console log. The subscription is running fine (I think) because if I put a console log on publication I got a right results. It’s just cant update the client data. Maybe because the meteor only observed the update and insert event on actual collection and not the query results of publication? If that’s so then I think it’ll be good to add a feature where it’ll also watch the difference of data output of publication and the temporary data on client side.

Nope, it was there, I just didn’t include it here. The publication returns correct data and that should update the client side but it isn’t. No errors it’s just can’t update the client side with the updated results of publication.

Can you post the contents of your package.json?

here’s the lists of packages.

package.json file

{
  "name": "jti-latest",
  "private": true,
  "scripts": {
    "start": "meteor run"
  },
  "dependencies": {
    "@babel/runtime": "^7.0.0-beta.49",
    "babel-runtime": "^6.26.0",
    "base64-img": "^1.0.3",
    "base64-stream": "^0.1.3",
    "bcrypt": "^0.8.7",
    "blob": "0.0.4",
    "core-js": "^2.5.1",
    "cron": "^1.3.0",
    "extract-zip": "^1.6.5",
    "html-docx-js": "^0.3.1",
    "image-size": "^0.6.1",
    "imap": "^0.8.19",
    "imap-simple": "^4.0.0",
    "install": "^0.10.4",
    "jszip": "^3.1.5",
    "mail-listener2": "^0.3.1",
    "mailparser": "^2.2.0",
    "meteor-node-stubs": "^0.4.1",
    "mongodb-backup-juvyc": "^1.6.9",
    "myob": "^0.3.16",
    "node-pdftk": "^1.2.1",
    "node-xlsx": "^0.12.0",
    "npm": "^5.6.0",
    "pdffiller": "0.0.10",
    "react": "^15.6.2",
    "react-dom": "^15.6.2",
    "readable-stream": "^2.3.3",
    "resize-img": "^1.1.2",
    "rimraf": "^2.6.2",
    "twilio": "^3.11.0",
    "url-exists": "^1.0.3",
    "wkhtmltopdf": "^0.3.4",
    "xero": "0.0.8"
  }
}

packages file

jquery@1.11.10                        # 2016-10-26 https://atmospherejs.com/meteor/jquery
mrt:jquery-ui                 # 2014-08-04 https://atmospherejs.com/mrt/jquery-ui
fortawesome:fontawesome
fourseven:scss
materialize:materialize
service-configuration@1.0.11  # 2014-08-04 https://atmospherejs.com/meteor/service-configuration
aldeed:collection2            # 2016-08-23 https://atmospherejs.com/aldeed/collection2
meteor-base@1.4.0             # 2017-10-28 https://atmospherejs.com/meteor/meteor-base - Packages every Meteor app needs to have
mobile-experience@1.0.5       # 2017-09-26 https://atmospherejs.com/meteor/mobile-experience - Packages for a great mobile UX
mongo@1.5.0                   # The database Meteor supports right now
blaze-html-templates@1.0.4    # Compile .html files into Meteor Blaze views
reactive-var@1.0.11           # Reactive variable for tracker
tracker@1.2.0                 # Meteor's client-side reactive programming library

standard-minifier-css@1.4.1   # CSS minifier run for production mode

es5-shim@4.8.0               # ECMAScript 5 compatibility for older browsers.
ecmascript@0.11.0              # Enable ECMAScript2015+ syntax in app code
shell-server@0.3.1            # Server-side component of the `meteor shell` command

accounts-password@1.5.1
check@1.3.1
http@1.4.1

# momentjs:moment
mrt:inputmask
ovcharik:alertifyjs
session@1.1.7
simple:rest
anonyfox:mmenu2
react-template-helper
mrt:googlemaps
mrt:moment-timezone
gwendall:body-events
teamon:tinymce
meteorhacks:aggregate
standard-minifier-js@2.3.4
dynamic-import@0.4.0
email@1.2.3
mrt:meteor-nodemailer
peerlibrary:aws-sdk
edgee:slingshot
chfritz:filedrop
base64@1.0.11
iron:router
mrt:fancybox
jts:personnel-invoices
jts:insurance-invoices
jts:manage-form-fields
jts:accounting-api
jts:procedure-codes
jts:report-templates
jts:scope-templates
jts:job-list-report
jts:supervisors-booking
jts:jobs-not-booked-in
jts:view-schedules
jts:phone-calls-report
jts:general-logs
jts:accounting-personnel-invoices-report
jts:accounting-insurance-invoices-report
jts:performance-chart
jts:percolor-stats
meteorhacks:unblock
jts:receive-payment
underscore

It’s not the list of packages I wanted, it’s the package.json - all of it.

The first lists is what you are asking I think it’s from package.json file

You’re right - sorry - trying to read it on my phone isn’t easy!

Interesting! I wouldn’t have thought Meteor supported MongoDB views at all.

It sounds like views just use MongoDB’s aggregation pipeline, which isn’t supported in subscriptions. [1]

[1] https://docs.mongodb.com/manual/core/views/#view-creation

@nathan_muir is correct. Reactive aggregations are only possible using packages such as jcbernack:reactive-aggregate and tunguska:reactive-aggregate.

Those packages build on Meteor’s pub/sub API to provide reactive aggregation livedata to the client. I haven’t tried views yet, but they appear at first sight to be broadly compatible with normal collection operations. Given that the latest official nodejs MongoDB driver has no explicit support for views, I suspect they’re supposed to work transparently and it wouldn’t be too difficult to get them to work in Meteor.