Here is a problem that I dont know what will be the syntax for insert. For ID I am using userID and location is just a part of a big schema. Here is the the complete schema:
ComplaintSchema = new SimpleSchema({
prob_cat: {
type: String,
label: “Select a category”,
allowedValues: [‘Road’, ‘Footpath’, ‘Street Light’, ‘Median’]
},
prob_type: {
type: String,
label: “Select the problem”,
allowedValues: [‘Broken’, ‘Absent’]
},
desc: {
type: String,
label: “Description”
},
author: {
type: String,
label: “Author”,
autoValue: function () {
return this.userId;
},
autoform: {
type: “hidden”,
omit: true
}
},
loc: {
type: Object,
index: ‘2dsphere’,
label: “Location”,
autoform: {
type: “hidden”,
omit: true
}
},
“loc.type”: {
type: String,
allowedValues: [“Point”],
label: “Start location type”
},
“loc.coordinates”: {
type: [Number],
minCount: 2,
maxCount: 2,
decimal: true,
autoValue: function () {
var lat = document.getElementById(“latitude”).value;
var lng = document.getElementById(“longitude”).value;
var location1 = [lat, lng];
return location1;
}
},
// Force value to be current date (on server) upon insert
// and prevent updates thereafter.
createdAt: {
type: Date,
label: “Select the date”,
autoValue: function () {
if (this.isInsert) {
return new Date();
} else if (this.isUpsert) {
return {$setOnInsert: new Date()};
} else {
this.unset(); // Prevent user from supplying their own value
}
},
autoform: {
type: “hidden”,
omit: true
}
},
// Force value to be current date (on server) upon update
// and don’t allow it to be set upon insert.
updatedAt: {
type: Date,
autoValue: function () {
if (this.isUpdate) {
return new Date();
}
},
denyInsert: true,
optional: true,
autoform: {
type: “hidden”,
omit: true
}
},
// Whenever the “content” field is updated, automatically
// update a history array.
updatesHistory: {
type: [Object],
optional: true,
autoValue: function () {
var content = this.field(“content”);
if (content.isSet) {
if (this.isInsert) {
return [{
date: new Date(),
content: content.value
}];
} else {
return {
$push: {
date: new Date,
content: content.value
}
};
}
} else {
this.unset();
}
},
autoform: {
type: “hidden”,
omit: true
}
},
‘updatesHistory.$.date’: {
type: Date,
optional: true
},
‘updatesHistory.$.content’: {
type: String,
optional: true
}
});
The user give only prob_type, prob_cat and desc fields, rest it is auto generated and thus hidden.
But when the user click on submit button, it should take the coordinates of the same from the previous template.
How should I do it then?