How to implement a key-value type in simple chema

Hi guys. I’m a newbie to Meteor. I want to add a key-value type in my simple schema, with values like:

{"tag1" : 0.10, "tag2": 0.23, "tag3" : 0.78.......}

I think one option is type Object, but I’m not sure how to implement it here. an anyone provide a simple example? Thanks a lot!

Not sure what exactly you want to achieve but if you want a collection that is a key/value store used to lookup values then I’d keep records like this:

new SimpleSchema({
  k: { type: String, unique: true},
  v: { type: Object } 
});

If you have a fair few keys and use these for lookup, then you might want to use Collection._ensureIndex, to ensure quick retrieval.

1 Like