标签: meteor-collection2

使用流星简单模式在字段中存储任意对象

我有一个字段的架构type: Object.但每当我进行插入时,该对象都是空的.

这是我的架构

Contacts.attachSchema(new SimpleSchema({
    firstName: {
        type: String,

    },
    lastName: {
        type: String,
        optional: true
    },
    twitterFriend: { // this field
        type: Object,
        optional: true
    }
}));
Run Code Online (Sandbox Code Playgroud)

即使这样做Contacts.insert({firstName: 'Mustafa', twitterFriend: {test: 'this should be stored'}}).这是行不通的.

meteor meteor-collection2

12
推荐指数
1
解决办法
3676
查看次数

使用Meteor单独进行表单验证

我正在使用collection2,我试图让它来处理验证是一种特定的方式.我有一个看起来像这样的配置文件架构:

Schema.UserProfile = new SimpleSchema({
    name: {
        type: String,
        optional: false
    }
    location: {
        type: String,
        optional: true
    }
    gender: {
        type: String,
        optional: false
    }
});

Schema.User = new SimpleSchema({
    username: {
        type: String,
        optional: true
    },
    emails: {
        type: Array,
        optional: true
    },
    "emails.$": {
        type: Object
    },
    "emails.$.address": {
        type: String,
        regEx: SimpleSchema.RegEx.Email
    },
    "emails.$.verified": {
        type: Boolean
    },
    createdAt: {
        type: Date
    },
    profile: {
        type: Schema.UserProfile,
        optional: true
    },
    services: {
        type: Object, …
Run Code Online (Sandbox Code Playgroud)

meteor meteor-collection2 simple-schema

11
推荐指数
1
解决办法
313
查看次数

未在启动时自动创建流星集合并且自动形式不会发布到mongo db

我是meteor和mongo db的新手.我正在使用meteor@1.3.4.1申请.我正在创建一个名为'/imports/api/collections/recipe.js'的文件.在这里,我创建一个集合并将此文件导入'/server/main.js'和'/client/main.js'.在recipe.js中,我只发布Recipe集合,然后在我的客户端文件中我订阅它.直到这一点,一切都是正确的.然后我使用autoform创建一个表单,它运行良好并创建.但这种形式永远不会发布.

首先,我的假设是当服务器启动时,那时我的数据库应该创建一个名为recipe的集合,但事实并非如此.

其次,为什么autoform不起作用?我认为这是因为第一个原因.

在客户端,我通过蒙古(流星玩具)看到我的食谱收藏.

我的食谱文件 - '/imports/api/collections/recipe.js':

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

var RecipesCollection = new Mongo.Collection('recipes');

RecipesCollection.allow({
    insert(userId, doc){
        return !!userId;
    }
})

var RecipeSchema = new SimpleSchema({
    name: {
        type: String,
        label: "Name"
    },
    desc: {
        type: String,
        label: "Description"
    },
    author: {
        type: String,
        label: "Author",
        autoValue(){
            return this.userId
        },
        autoform:{
            type: "hidden"
        }
    },
    createdAt: {
        type: Date,
        label: "Created At",
        autoValue(){ …
Run Code Online (Sandbox Code Playgroud)

mongodb meteor meteor-blaze meteor-autoform meteor-collection2

9
推荐指数
1
解决办法
517
查看次数

返回表达式中不存在最常见的类型

当我在angular2-meteor项目中使用Collection2时,来自demo的这些代码总是在终端中给我警告:

返回表达式中不存在最常见的类型.

我该如何改进代码?谢谢

{
  createdAt: {
    type: Date,
    autoValue: function() {
      if (this.isInsert) {
        return new Date();
      } else if (this.isUpsert) {
        return {$setOnInsert: new Date()};
      } else {
        this.unset();
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

meteor typescript meteor-collection2 angular2-meteor angular

8
推荐指数
1
解决办法
2438
查看次数

SimpleSchema或collection2中的ObjectId

我正在玩meteor并开始使用simple-schema和collection2.我从猫鼬和节点移动所以我的问题可能是一点点菜鸟,所以忍受我.

在mongoose中我可以添加一个名为schema.ObjectId的类型,在某些字段中模拟引用,但我没有在collection2中看到任何这样的含义.那有什么快速解决方案吗?

使用type:String这个场景是个好主意吗?

提前致谢

javascript mongodb node.js meteor meteor-collection2

7
推荐指数
1
解决办法
976
查看次数

如何使用meteorjs中的accounts-password包向用户集合添加collection2架构?

所以,我刚刚开始了一个流星项目,并且已经包含了帐户密码包.该软件包仅支持少量密钥.我想将一个新的SimpleSchema添加到带有更多字段的users集合中.

我不会创建另一个用户集合实例

@users = Mongo.Collection('users');
//Error: A method named '/users/insert' is already defined
Run Code Online (Sandbox Code Playgroud)

我可以附加一个模式,但将强制保留很多字段可选,否则可能无法注册默认包.

我可以添加simpleSchema而不使其他字段可选,但仍能正常登录吗?

或者这个案子还有其他工作吗?

提前感谢您的帮助

javascript mongodb meteor meteor-accounts meteor-collection2

7
推荐指数
1
解决办法
887
查看次数

Meteor使用namedContext将addInvalidKeys添加到AutoForm表单返回错误

我有以下SimpleSchema,我试图添加自定义验证以验证输入重复的客户名称,但每当我尝试保存新客户时,我收到错误:

提供调用'adminCheckNewCustomerName'结果的异常:TypeError:无法读取null的'namedContext'属性

有人可以请告诉我我在做错了什么/在这里缺少来验证客户名称是否有重复记录?谢谢

schema.js:

AdminSection.schemas.customer = new SimpleSchema({
    CustomerName: {
        type: String,
        label: "Customer Name",
        unique: true,
        custom: function() {
            if (Meteor.isClient && this.isSet) {
                Meteor.call("adminCheckNewCustomerName", this.value, function(error, result) {
                    if (result) {
                        Customer.simpleSchema().namedContext("newCustomerForm").addInvalidKeys([{
                            name: "CustomerName",
                            type: "notUnique"
                        }]);
                    }
                });
            }
        }
    }
});

UI.registerHelper('AdminSchemas', function() {
    return AdminSection.schemas;
});
Run Code Online (Sandbox Code Playgroud)

form.html:

{{#autoForm id="newCustomerForm" schema=AdminSchemas.customer validation="submit" type="method" meteormethod="adminNewCustomer"}}
   {{>afQuickField name="CustomerName"}}
   <button type="submit" class="btn btn-primary">Save Customer</button>
{{/autoForm}}
Run Code Online (Sandbox Code Playgroud)

collections.js:

this.Customer = new Mongo.Collection("customers");
Run Code Online (Sandbox Code Playgroud)

javascript meteor meteor-autoform meteor-collection2 simple-schema

6
推荐指数
1
解决办法
1084
查看次数

在Autoform中使用对象作为选项

在我的Stacks架构中,我有一个dimensions定义如下的属性:

dimensions: {
    type: [String],
    autoform: {
        options: function() {
            return Dimensions.find().map(function(d) {
                return { label: d.name, value: d._id };
            });
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这非常有效,并且使用Mongol我能够看到通过表单插入数据的尝试运行良好(在这种情况下,我选择了两个要插入的维度)

蒙古形象

然而,我真正的是存储实际维度对象而不是密钥的数据.像这样的东西:

[蒙古好[2]

要努力实现这一点,我改变了type:[String]type:[DimensionSchema]value: d._idvalue: d.这里的想法是我告诉表格我期待一个对象,现在我正在返回对象本身.

但是当我运行它时,我在控制台中收到以下错误.

Meteor当前不支持ObjectID以外的对象作为ID

稍微调整一下并type:[DimensionSchema]改为type: DimensionSchema我在控制台中看到一些新错误(可能是当它type是一个阵列时它们会被埋没

控制台图像

所以似乎autoform试图获取我想要存储在数据库中的值并尝试将其用作id.有关最佳方法的任何想法吗?

这里参考是我的 DimensionSchema

export const DimensionSchema = new SimpleSchema({
    name: {
        type: String,
        label: "Name"
    },
    value: {
        type: Number,
        decimal: true,
        label: "Value",
        min: 0

    },
    tol: …
Run Code Online (Sandbox Code Playgroud)

mongodb meteor meteor-autoform meteor-collection2 simple-schema

6
推荐指数
1
解决办法
230
查看次数

使用autoform验证Meteor方法的模式

我正在使用autoform,collection2.我想使用方法调用类型进行插入/更新,因为我想在保存到服务器中的数据库之前添加其他字段.SimpleSchema会检查客户端中的数据,但是如何根据服务器端的模式检查数据呢?我添加新数据的方法如下:

Meteor.methods({
  companyAdd: function (companyAttr) {

    // add additional fields to document

    var currentDate = new Date(); 

    var company = _.extend(companyAttr, {
        createdBy: user._id,
        createdAt: currentDate
    });

    var newCompanyId = Companies.insert(company);
    return {_id: newCompanyId};
  }
}
Run Code Online (Sandbox Code Playgroud)

javascript meteor meteor-autoform meteor-collection2

5
推荐指数
1
解决办法
735
查看次数

如何以"插入"形式传递字段的默认值?

如何以"插入"形式传递字段的默认值?

我正在使用Meteor的软件包:Autoform,Collections2和Simple-Schema.

我的过程是:

  1. 用户在页面上的列表中选择一些值,然后
  2. 打开"插入",我希望使用用户在上一步中选择的值初始化一个字段.

无法弄清楚如何使用URL(或任何其他方式)传递参数.问题是如何使用值初始化表单.

假设我有一个URL:

http://localhost:3000/activity/new/Sport
Run Code Online (Sandbox Code Playgroud)

=============== router.js:

...
Router.map(function () {
    ...
    this.route('newActivity', {
        path: '/activity/new/:tag',
        data: function() {
            Session.set('tag', this.params.tag);
            return null;
        }
    });
    ...
Run Code Online (Sandbox Code Playgroud)

=============== models/activity.js

...
Activities = new Meteor.Collection("activities", {
    schema: {
        title: {
            type: String,
            label: '????????'
        },
        ...
        tag: {
            type: String,
            label: '???'
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

================ templates/avtibity.js

...
Template.newActivity.helpers({
    defaultTag: function() {
        return Session.get('tag');
    }
});
...
Run Code Online (Sandbox Code Playgroud)

================ templates/activity.html

...
<template name="newActivity">
    <h1>Create new Activity!</h1>
    {{#autoForm collection="Activities" id="insertActivityForm" type="insert"}} …
Run Code Online (Sandbox Code Playgroud)

meteor meteor-autoform meteor-collection2 simple-schema

4
推荐指数
1
解决办法
3767
查看次数