I’m using autoforms, collection2 and SimpleSchema. I’d like to segregate the population of default values so that they can be changed at a later point in time directly in mongo rather than hard-coding them in the schema itself. I tried the below approach but it doesn’t seem to be working. The console log says “undefined”. How do I go about this?
Schema:
Defaults = new Mongo.Collection('Defaults');
[...]
"lock-time.interval":{
type: Number,
decimal: false,
min: 30, max:3600,
defaultValue: function() {
**console.log(
Defaults.findOne({},{_id:0,"lock-time-interval":1}));
return Defaults.findOne(Defaults.findOne({},{_id:0,"lock-time-interval":1}));**
}
}
[...]
Mongo Collection:
meteor:PRIMARY> db.Defaults.findOne({});
{
"_id" : ObjectId("5768f728708012bb60501f0b"),
"lock-time-interval" : 300
}
meteor:PRIMARY>
--------------------UPDATE-----------------------
I also tried the below after restructuring the mongo record. the console is returning something like an array object. Upon further reading, it does make sense as it’s mentioned that an array will be returned. How exactly do I extract the needed value from the array?
"lock-time.interval":{
type: Number,
decimal: false,
min: 30, max:3600,
defaultValue: function() {
console.log(
Defaults.find().map(function(c){
return {value: c.value};
}))
}
},
MongoDB
meteor:PRIMARY> db.Defaults.findOne({});
{
"_id" : ObjectId("57690508708012bb60501f0d"),
"name" : "lock-time-interval",
"value" : 300
}
[ + @hwillson ]