Interactions with mongo collections fails on Cordova


#1

Hello guys, I’m trying to build an mobile app to read a qrcode and subtract a value in a collection.
To read the qrcode I’m using Cordova’s BarcodeScanner plugin, so.

How I’m building the app:

meteor build ../redpass-builds --server=http://meteor-mobile.com:3000  --mobile-settings=settings.json

How I reach the page:

FlowRouter.route('/operador/validacao/',{
    subscriptions: function(params, queryParams) {
        this.register('events', Meteor.subscribe('AllEventsIsTodayMoreOneDay'));
        this.register('transactions', Meteor.subscribe('AllTransactions'));
        this.register('lotes', Meteor.subscribe('AllLotes'));
    },
    action: function(params) {
        FlowLayout.render('Private', {main: "TicketValidation"});
    }
});

How my template looks like:

<template name="TicketValidation">
    <div style="text-align: center">
        {{#if isReady "events"}}
            {{#if isReady "transactions"}}
                {{#if isReady "lotes"}}
                    <button type="button" class="scan btn btn-primary btn-lg"><i class="fa fa-qrcode fa-5x"></i></button>
                {{/if}}
            {{/if}}
        {{/if}}
    </div>
</template>

How I read the qrcode:

Template.TicketValidation.events({
    'click .scan':function(){
        cordova.plugins.barcodeScanner.scan(
            function (result) {
                var transactionId = result.text;
                alert("transactionId:"+transactionId);

                var transactions = Transactions.find({}).fetch().count();
                alert("transactions:"+transactions);

                var transaction = Transactions.findOne({_id:transactionId});
                alert(transaction['card_holder_name']);

                var quantity = parseInt(transaction.quantity);
                if(quantity>0){
                    var remainder = quantity-1;
                    Transactions.update({_id:transactionId},{$set:{quantity:remainder}})
                    alert("Ingresso válido!")
                }else{
                    alert("Esse ingresso já foi utilizado!")
                }
            },
            function (error) {
                alert("Não foi possível verificar o ingresso!");
            }
        );
    }
});

Ok! Qrcode reading works fine! The alert with transactionId is fired nicely but, for some reason the next line that interacts with Transactions collection doesn’t, I don’t know why. Anyone has some idea?

Tks!


#2

I found the problem, but not the solution.

The problem is that for some reason, when app is rendered Meteor.status().status is connected but after few seconds the status down to waiting and goes to connecting and still connecting forever…