This might be a simple javascript question. I finally got this meteor upsert statement working, except in the cases where a matching record does not already exist. It works if I replace chan._id with '' or null, so what I want to do is simply use null in place of chan._id in the cases where chan finds no existing record. I just don't know how to write such a thing.
//client
var chfield = t.find('#today-channel').value,
chan = Today.findOne({channel: chfield})
Meteor.call('todayUpsert', chan._id, {
channel: chfield,
admin: Meteor.userId(),
date: new Date(),
});
//client and server
Meteor.methods({
todayUpsert: function(id, doc){
Today.upsert(id, doc);
}
});