2

I have setup my collections like this using Simple Schema :

SubLinkSchema = new SimpleSchema({
    name: {
        type: String,
        label: 'Link Name',
        unique: false
    },
    link: {
        type: String,
        regEx: SimpleSchema.RegEx.Url,
        label: 'Custom Link',
        optional: true,
        autoform: {
            class: 'sub-custom-link'
        }
    }

});

LinkSchema = new SimpleSchema({
    name: {
        type: String,
        label: 'Link Name',
        unique: false
    },
    link: {
        type: String,
        regEx: SimpleSchema.RegEx.Url,
        label: 'Custom Link',
        optional: true,
        autoform: {
            class: 'main-custom-link'
        }
    },
    subLinks: {
        optional: true,
        label: 'Sub Links',
        unique: false,
        type: [SubLinkSchema]
    }
});

In here, the problem is, the sublinks do not get an ID. Its hard to update them without an id. So, how can I generate a unique ID per sublink (embedded document)?

THpubs
  • 7,804
  • 16
  • 68
  • 143

2 Answers2

7

use an autovalue field in the SimpleSchema

see ref here: https://github.com/aldeed/meteor-collection2#autovalue

and example:

subLinkID: {
    type: String,
    autoValue: function() {
        return Meteor.uuid();
    }
  }
MrE
  • 19,584
  • 12
  • 87
  • 105
0

It should go with the

Meteor.uuid()

Thai Tran
  • 9,815
  • 7
  • 43
  • 64