Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor 创建新用户帐户时出错_Meteor_Meteor React - Fatal编程技术网

Meteor 创建新用户帐户时出错

Meteor 创建新用户帐户时出错,meteor,meteor-react,Meteor,Meteor React,当用户第一次创建他们的帐户时,我试图将一个新集合插入数据库,但是,我得到了一个错误 调用方法“createUser”TypeError时出现异常:无法读取未定义的属性“insert” 我在过去使用过类似的代码,没有这个问题 路径:imports/startup/server/newUser.js import { Meteor } from 'meteor/meteor'; import { Roles } from 'meteor/alanning:roles'; import { Accou

当用户第一次创建他们的帐户时,我试图将一个新集合插入数据库,但是,我得到了一个错误

调用方法“createUser”TypeError时出现异常:无法读取未定义的属性“insert”

我在过去使用过类似的代码,没有这个问题

路径:
imports/startup/server/newUser.js

import { Meteor } from 'meteor/meteor';
import { Roles } from 'meteor/alanning:roles';
import { Accounts } from 'meteor/accounts-base';
import { Documents } from '../../api/documents/documents.js';

Accounts.onCreateUser((options, user) => {
      if (options.profile) {
        user.profile = options.profile;
      }

      Documents.insert({
        title: "Test Title",
        body: "Test Body"
      })

      return user;
    });
import { Mongo } from 'meteor/mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
import { Factory } from 'meteor/dburles:factory';

const Documents = new Mongo.Collection('Documents');
export default Documents;

Documents.allow({
  insert: () => false,
  update: () => false,
  remove: () => false,
});

Documents.deny({
  insert: () => true,
  update: () => true,
  remove: () => true,
});

Documents.schema = new SimpleSchema({
  title: {
    type: String,
    label: 'The title of the document.',
  },
  body: {
    type: String,
    label: 'The body of the document.',
  },
});

Documents.attachSchema(Documents.schema);
路径:
imports/api/documents/documents.js

import { Meteor } from 'meteor/meteor';
import { Roles } from 'meteor/alanning:roles';
import { Accounts } from 'meteor/accounts-base';
import { Documents } from '../../api/documents/documents.js';

Accounts.onCreateUser((options, user) => {
      if (options.profile) {
        user.profile = options.profile;
      }

      Documents.insert({
        title: "Test Title",
        body: "Test Body"
      })

      return user;
    });
import { Mongo } from 'meteor/mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
import { Factory } from 'meteor/dburles:factory';

const Documents = new Mongo.Collection('Documents');
export default Documents;

Documents.allow({
  insert: () => false,
  update: () => false,
  remove: () => false,
});

Documents.deny({
  insert: () => true,
  update: () => true,
  remove: () => true,
});

Documents.schema = new SimpleSchema({
  title: {
    type: String,
    label: 'The title of the document.',
  },
  body: {
    type: String,
    label: 'The body of the document.',
  },
});

Documents.attachSchema(Documents.schema);

如果您使用的是MongoDB,则必须首先声明文档集合,如下所示:

var Documents = new Mongo.Collection('documents');

然后您应该能够使用常见的MongoDB操作。

因此,答案非常简单。我在流星论坛上发布了这篇文章,@jamgold提供了解决方案。找到答案

我用过:

从“../../api/Documents/Documents.js”导入{Documents}

使用括号导入不正确,因为我使用的是
导出默认文档
。应该是:


从“../../api/Documents/Documents.js”导入文档

我使用的是来自aldeed的简单scheam。我认为新集合是在api目录下的Documents下定义的。您是从react客户端调用这些指令,还是从meteor服务器调用这些指令?我认为您必须首先使用服务器上的
new SimpleSchema
来定义它。您是在定义集合吗?