Home Ask Login Register

Developers Planet

Your answer is one click away!

Manuscript80 February 2016

Meteor method clobbers subscribed query

I'm using Meteor with React. When I load a page, Iron Router creates a document in a collection. It then uses a Meteor.method to look up the user's permissions and set them on the document through and update. At the same time, the client page is loading and runs queries for the document in the collection.

It seems that the Meteor.method code is clobbering the query on the client. Through multiple queries, the document exists and I can console.log() it. Then suddenly I get "undefined". The document still exists because I can query it from another Meteor.call. I have used publish/subscribe, but the client can't see it.

Here's some of my code (files combined for simplicity):

Editors = new Mongo.Collection('editors');

if (Meteor.isServer())
    Meteor.publish('editors', function (editorId) {
        return Editors.find(editorId) || this.ready();
    });

    Meteor.methods({
        setEditorMode: function (editorId, userId) {
            var editor = Editors.findOne(editorId);
            var role = Roles.find({
                doc_id: editor.manuscriptId,
                user_id: userId
            }).fetch()[0];
            var defaultEditorMode = "readOnly";

            if (role !== null && role.role == 'owner' || role.role == 'contributor') {
                defaultEditorMode = "readWriteComment";
            } else if (role !== null && role.role == 'reviewer') {
                defaultEditorMode = "readComment";
            }

            console.log(editor);
            Editors.update(editor._id, {
                $set: {
                    defaultEditorMode: defaultEditorMode,
                    editorMode: defaultEditorMode
                }
            });
            console.log(Editors.findOne(editor._id);
        }
    });
}

if (Meteor.isClient()) {
    Router.route('/documents/:id/edit', function () {
        var editorId;

        manuscriptId = this.params.id;

        this.wait(/* Doing som        

Answers


Manuscript80 February 2016

Thanks to @ko0stick, I figured out that I needed to place my Meteor.subscribe code inside of getMeteorData

Post Status

Asked in February 2016
Viewed 3,124 times
Voted 7
Answered 1 times

Search




Leave an answer


Quote of the day: live life