meteor-vue / vue-meteor

🌠 Vue first-class integration in Meteor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

error caught on publication: sdocs : Can't publish a cursor from a collection without a name.

welkinwong opened this issue · comments

error

W20191012-12:44:22.370(8)? (STDERR) error caught on publication: sdocs : Can't publish a cursor from a collection without a name.
(need reload web)

collection

import {Mongo} from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';

const Sdocs = new Mongo.Collection('sdocs');

const sdocsSchema = new SimpleSchema({
  type: {
    type: String,
    allowedValues: ['folder']
  },
  name: {
    type: String
  },
  createAt: {
    type: Date,
    autoValue: function () {
      if (this.isInsert) {
        return new Date();
      } else {
        this.unset();
      }
    }
  },
  modifyAt: {
    type: Date,
    autoValue: function () {
      if (this.isInsert || this.isModifier) {
        return new Date();
      } else {
        this.unset();
      }
    }
  }
});

Sdocs.attachSchema(sdocsSchema);

export default Sdocs;

publications.js

import {Meteor} from 'meteor/meteor';
import SimpleSchema from 'simpl-schema';
import Sdocs from './collection';

Meteor.publish('sdocs', function () {
  return Sdocs.find({}, {
    sort: {createAt: -1}
  });
});

I’m subscribing with vue-meteor-tracker

<script>
  import Sdocs from '/api/sdocs/collection';
  import createFolder from '/api/sdocs/methods';

  export default {
    methods: {
      newFolder () {
        createFolder.call({name: '2345'})
      }
    },
    meteor: {
      $subscribe: {
        ['sdocs']: []
      },
      SdocsCursor () {
        return Sdocs.find({}, {
          sort: {createAt: -1}
        });
      }
    }
  }
</script>

/.meteor/packages

# Meteor packages used by this project, one per line.
# Check this file (and the other files in this directory) into your repository.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

meteor-base@1.4.0             # Packages every Meteor app needs to have
mobile-experience@1.0.5       # Packages for a great mobile UX
mongo@1.6.2                   # The database Meteor supports right now
reactive-var@1.0.11            # Reactive variable for tracker
tracker@1.2.0                 # Meteor's client-side reactive programming library

standard-minifier-css@1.5.3   # CSS minifier run for production mode
standard-minifier-js@2.4.1    # JS minifier run for production mode
es5-shim@4.8.0                # ECMAScript 5 compatibility for older browsers
ecmascript@0.12.4              # Enable ECMAScript2015+ syntax in app code
shell-server@0.4.0            # Server-side component of the `meteor shell` command

insecure@1.0.7                # Allow all DB writes from clients (for prototyping)
akryum:vue-component
akryum:vue-ssr
static-html
aldeed:collection2
mdg:validated-method

/packages.js

{
  "name": "superdocs",
  "private": true,
  "scripts": {
    "start": "meteor run",
    "test": "meteor test --once --driver-package meteortesting:mocha",
    "test-app": "TEST_WATCH=1 meteor test --full-app --driver-package meteortesting:mocha",
    "visualize": "meteor --production --extra-packages bundle-visualizer"
  },
  "dependencies": {
    "@babel/runtime": "^7.3.4",
    "element-ui": "^2.12.0",
    "meteor-node-stubs": "^0.4.1",
    "normalize.css": "^8.0.1",
    "simpl-schema": "^1.5.6",
    "vue": "^2.6.10",
    "vue-meteor-tracker": "^2.0.0-beta.5",
    "vue-router": "^3.1.3"
  },
  "devDependencies": {},
  "meteor": {
    "mainModule": {
      "client": "client/main.js",
      "server": "server/main.js"
    },
    "testModule": "tests/main.js"
  }
}

please help

I fixed this by making sure I only subscribe on the client. Also, I moved the subscription to the created lifecycle hook:

created() {
    if (Meteor.isClient) {
        this.$subscribe('subscriptionWithNoParameter', []);
        this.$subscribe('subscriptionWithParameter', () => [this.someParameter]);
    }
},

No more errors :)

I fixed this by making sure I only subscribe on the client. Also, I moved the subscription to the created lifecycle hook:

created() {
    if (Meteor.isClient) {
        this.$subscribe('subscriptionWithNoParameter', []);
        this.$subscribe('subscriptionWithParameter', () => [this.someParameter]);
    }
},

No more errors :)

Thanks, no warning