Meteor/Blaze: How to create a new collection on form event

Hi all,

How do I create a new collection form event? For example my user story is:

    • click on home page to veiw all current inventories (lists/collections)
    • click on “create new inventory”
    • new page with new form for inventory title and a few other values
    • on submit the app creates new mongo collection using the “ListTitle” value from the submitted for as its name.
    • app inserts new record into the collection with the input values from the form.
    • new collectio9n appears in their dashaboard on he app so they can edit, update or remove the list.

How Do I accomplish steps 4 and 5? is it as simple as:

Template.AddNewList.events({
// when the form is submitted
’submit .new-list’(event) {
[input value from the form] = new Mongo.Collection(’[input value from the form]’);

const myData = {
   key1: "listTitle.value",
}

[input value from the form] .insert(myData);

var findCollection = [input value from the form] .find().fetch();
console.log(findCollection);

}

});

I’m not sure if it’s a good idea to create a whole new Collection for your use case.

Why not choosing to use a different approach :

Let say you create 1 collection called “Lists” : it will contains your lists definition with for each an id, name, timestamp, creatorUID, etc…

Then for your Items, you can choose to create another collection which will contain every items of every “Lists” each Item having the Id of the List it belongs to. Or you can embed them as an array of subdocuments of your “Lists” elements.

2 Likes

Thanks mate, I’ll explore that approach instead and then cycle back if I have issues.

Indexed queries are fast as hell compared to unindexed queries. You’re suppose to make those indexes, and those indexes cost space, and DB space is not at all cheap. Each collection as well as document has some overhead besides that.

Aggregations are what personalize things for user if you’re looking to do that with every new collection, and they’re no less cheap, but not as slow.