simple-schema

Meteor collection2 array with Strings and Object

余生颓废 提交于 2020-01-05 03:49:07
问题 i'm using Meteor with collection2 and I have an array that looks like this: productTypes = ["string1", "string2", "string3", {Other: "test"}] Essentially there will be anywhere from 0 to 7 strings in the array, and Other: 'Test' may or may not be present So i'm trying to make a schema that handles that case. Is there a way to tell it that there will be strings and an object within an array? I've tried const residentSchema = new SimpleSchema({ productTypes: {type: [String, Object], optional:

SimpleSchema: Conditionally required field is not working

狂风中的少年 提交于 2019-12-25 09:28:16
问题 This is how I'm doing a validation using SimpleSchema with a conditionally required field ( module ). So this should only be required if type has the value 'start' client const module = 'articles', _id = 'bmphCpyHZLhTc74Zp' console.log(module, _id) // returns as expected 'articles' and 'bmphCpyHZLhTc74Zp' example.call( { type : 'start', module: module, _id : _id }, (error, result) => { if (error) console.log(error) } ) server example = new ValidatedMethod({ name : 'example', validate: new

Bind allowedValues to values from a collection in simple-schema

耗尽温柔 提交于 2019-12-24 15:03:04
问题 I'm using aldeed:simple-schema and here's the code: Cities = new Mongo.Collection('cities'); Cities.insert({ name: 'Oslo' }); Cities.insert({ name: 'Helsinki' }); Contact = new SimpleSchema({ city: { type: String, allowedValues: Cities.find().map((e) => e.name) // written ES6-style for readability; in fact, here goes an ES5 anonymous function definition } }); What it does is explicitly binds currently existing cities from Cities collection to Contact schema's certain field's allowed values,

How to add user id information in the schema and also hide form autoforms?

孤人 提交于 2019-12-24 12:50:25
问题 I am learning the ropes of Meteor and kind of lost here. I am using collections2, autoform for building my application. I want to store the collection along with user id information. So that when we retrieve the collection from the server, I want to show only the ones the user created not everything else. here is the schema. ExercisesSchema = new SimpleSchema({ "name": { type: String, label: 'Name' }, "workout.$.weight": { type: String, label: 'Weight' }, "workout.$.reps": { type: String,

How to add a relationship or reference with AutoForm in Meteor?

拈花ヽ惹草 提交于 2019-12-24 10:39:33
问题 I use meteor-autoform to insert documents in a collection. My Items has a field groupId . How can I insert this group id when I'm submitting my item form. <template name="itemForm"> {{#autoForm type="insert" collection=Collections.Items}} {{> afQuickField name="name"}} <div class="form-group"> <button type="submit" class="btn btn-primary">Add item</button> <button type="reset" class="btn btn-default">Reset Form</button> </div> {{/autoForm}} </template> I could create another field containing

Updating array of objects in mongodb

独自空忆成欢 提交于 2019-12-20 06:37:20
问题 I'm trying to update an array of objects in my simple-schema. Currently, it removes everything in the database and leaves behind: "careerHistoryPositions": [] My simple-schema looks like: const ProfileCandidateSchema = new SimpleSchema({ userId: { type: String, regEx: SimpleSchema.RegEx.Id }, careerHistoryPositions: { type: Array, optional: true }, 'careerHistoryPositions.$': { type: Object, optional: true }, 'careerHistoryPositions.$.uniqueId': { type: String, optional: true },

SimpleSchema is not a constructor

此生再无相见时 提交于 2019-12-20 03:52:30
问题 My app constantly crashes with this error. TypeError: SimpleSchema is not a constructor at attendances.js (imports/api/attendances/attendances.js:44:27) . I've googled it and the StackOverflow solution doesn't work. I'm running simpl-schema and Collection2 Can anyone tell me whats wrong here? import { Mongo } from 'meteor/mongo'; import SimpleSchema from 'simpl-schema'; const Attendances = new Mongo.Collection('attendances'); Attendances.debug = true; Attendances.allow({ insert: () => true,

How to dynamically change the value of an optional attribute of a field in Autoform / SimpleSchema?

心已入冬 提交于 2019-12-14 03:05:11
问题 I have a SimpleSchema instance with two fields: isApproved: { type: Boolean, defaultValue: false }, impactedSystems: { type: String, optional: true } I'd like to change the optional attribute of impactedSystems to false if isApproved is set to true . I've tried following the instructions in the docs but I can't get it to work. It suggests I add a custom function to impactedSystems like so (modified with my field names): custom: function () { var shouldBeRequired = this.field('isApproved')

Meteor Mongo - upsert and $inc with aldeed simple schema - 'update failed'

这一生的挚爱 提交于 2019-12-12 18:36:06
问题 I have an image gallery with a forward and backward-button. on a click on either of the buttons i want to upsert an entry in the local database with the times the image has been viewed (so i can later see which image has been viewed the most). This works perfectly without the Schema: 'click .btn-forward, click .btn-backward' (event, template) { Local.Viewed.upsert({ imageId: this._id }, { $setOnInsert: { imageId: this._id, imageName: this.name }, $inc: { timesViewed: 1 } }); } }); The Schema:

Array of objects passes validation but doesn't update collection

折月煮酒 提交于 2019-12-12 04:15:43
问题 My update method is passing the simple-schema validation test however it isn't updating my collection. I'm updating an array of objects. Example: array var arrayTest = [ { company: 'sdsd', uniqueId: 1500431892902, title: '', description: '', startDateMonth: '', startDateYear: '', endDateMonth: '', endDateYear: '', isCurrent: false, isDisabled: false, } ]; Validate: Array new SimpleSchema({ company: { type: String, optional: true }, uniqueId: { type: Number, optional: true }, title: { type: