简体   繁体   中英

In Meteor 1.3.x, how do you add a collection from within imports/api?

I have a collection of Appointments which I'm porting to the new 1.3 file structure. It is structured like the Todo app, but it is still not creating the Meteor collection.

/imports/api/appointments/appointments.js

import { Meteor } from 'meteor/meteor';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
import { Mongo } from 'meteor/mongo';

export const Appointments = new Mongo.Collection('appointments');

Appointments.deny({
  insert() { return true; },
  update() { return true; },
  remove() { return true; },
});

/imports/startup/server/index.js

import './register-api.js';

/imports/startup/server/register-api.js

import '../../api/appointments/methods.js';
import '../../api/appointments/appointments.js';
import '../../api/orgs/orgs.js';

Then, using "meteor mongo" and "show collections"

availability
emailvariables
invitations
meteor_accounts_loginServiceConfiguration
orgs
recurring
roles
services
system.indexes
users

What am I doing wrong?

new Mongo.Collection doesn't create a MongoDB collection automatically. You'll need to perform an insert to have it created. Like so:

Meteor.startup(() => {
  Appointments.insert({foo: 1});
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM