Autoform/collection2 replacement for VueJS

I have been writing several applications with Meteor/Blaze and find the autoform/collection2 packages immensely helpful.

I want to rewrite one of my bigger projects in VueJS and am wondering what to replace those packages with. Any suggestions?

1 Like

Looks like MongoDB supports native JSON schemas since v4. I was able to make it work, but it doesn’t seem completely supported by Meteors implementation of Mongo

  const db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
  let collections = db.collections().await();
  let collectionNames = collections.map((c) => { return c.s.name });
  if (collectionNames.indexOf('students') >= 0) {
    db.dropCollection('students');
    console.log('dropped students');
  }
  const students = db.createCollection("students", {
    validator: {
      $jsonSchema: {
        bsonType: "object",
        required: ["name"],
        properties: {
          _id: {},
          name: {
            bsonType: ["string"],
            description: "'name' is a required string"
          },
          graduated: {
            bsonType: ["bool"],
            description: "'graduated' is an optional boolean value"
          }
        },
        dependencies: {
          graduated: {
            required: ["mailing_address"],
            properties: {
              mailing_address: {
                bsonType: ["string"]
              }
            }
          }
        }
      }
    }
  }).await();

Students = new Mongo.Collection('students');

After that you can use Students just as any other collection, but on the client there is just a generic error. On the server it is possible to catch it

Meteor.methods({
  studentInsert(doc) {
      try {
        return Students.insert(doc);
      } catch(err) {
        throw new Meteor.Error(500, `${err.name} ${err.errmsg}`);
      }
  }
})