juanp_1982
juanp_1982

Reputation: 1007

how to get a collection in minimongo after a query

I'm working on a database monitoring App. in this app the user many kind of queries right after another. For this reason I'm subscribing every time (to pull only the information that he/she needs) the user makes a query, however it seems like the collection on the client side is not getting updated or refreshed this is my code:

//client side
var jobs_completed = new Meteor.Collection("GE_qstat_jobs_completed");
var criteria = {
       sort: {
           submission_time: 1
       },
       limit: 500,
       skip: 0,
       fields: {
           ClusterId: 0
       }
};
...
...
...
...
var subscribeToQueued = function (){
    Meteor.subscribe('queued', query, criteria, function(){
        console.log("       queued -> DONE");
        var myCursor = jobs_queued.find({});//<< the information is not updated in here
        var rows_num = myCursor.count();
        var tableInfo = myCursor.fetch();
        displayTable(tableInfo, rows_num);
   });
}
...
...
...
...
var displayTable = function(tableInfo, rows_num){
    var i = 1;
    tableInfo.forEach(function (row) {
        displayRow(row, i);
        i++;
    });
    ...
    ...
    ...
    ...
});   

//server side
Meteor.publish("queued", function(query, criteria){
    return jobs_queued.find(query, criteria);
});

query depend on the user's input but it looks something like this query = {} or like this

query = {
   submission_time: {
       $gte: Wed Aug 06 2014 00:00:00 GMT-0400 (EDT), 
       $lt: Wed Aug 06 2014 23:59:59 GMT-0400 (EDT)
   }, 
   JB_owner: {
       $in:["ahmei2", "alcsuo"]
   }, 
   JB_project: {
       $in:["acetyl", "bcf"]
   }, 
   JB_pe: "ivybridge"
   }

so, when the user makes a new request, what it's displayed, it's the content from the previous query, any idea how I can fix this???

Upvotes: 1

Views: 200

Answers (1)

Tomasz Lenarcik
Tomasz Lenarcik

Reputation: 4880

I think that the publish/subscribe model is just not good for your use case. Subscriptions are good if you are planning to watch a particular cursor for a longer time. If your users only want to test the results of a particular query I believe that doing it with a simple method call should be good enough. At least it's a lot simpler conceptually.

Upvotes: 1

Related Questions