0

I want to create a list for which I so far have this Schema:

new SimpleSchema({
    element:    { type: String, optional: true },
    note:       { type: String, optional: true },
    order:      { type: Number, optional: true }
});

But now I want to add groups, which also acts like an item:

Pancakes
Vegetables
    Tomatoes
    Salad
Orange juice

So 'Vegetables' is a group, which have two elements in it, but 'Vegetables' itself is sortable in the main, that means this example-category mainly consists of three elements: Pancakes, Vegetables and Orange juice. Vegetable can be slided down to display the content.

What is the easiest schema for this puprose I mean less nested SimpleSchema-elements - if it is possible without any nested schema?

What I want to do is, that an editor can select some elements on a list and put them to a group. All main elements and the group itself can be ordered by Drag'n drop. So I need the information of the element/group-order.

I hope I can explain what I need to do.

user3142695
  • 15,844
  • 47
  • 176
  • 332

1 Answers1

0

You are creating a tree. There are various ways to represent that in a database and in mongodb in particular: http://docs.mongodb.org/master/tutorial/model-tree-structures/

I often find the array of ancestors to be the best option.

Ian Mercer
  • 38,490
  • 8
  • 97
  • 133
  • Ok, how do I choose the best value for `_id`? As I have 1-20 Elements (dynamic), which has a title up to 250 characters... – user3142695 Sep 17 '15 at 22:47
  • Always use `ObjectId` (until you have good reason not to). Reusing some other field for an Id almost always leads to pain later on. – Ian Mercer Sep 18 '15 at 06:27