var keystone = require('keystone'),
async = require('async'),
KModel = keystone.list('KPosts');
function createContent(document, done) {
var newDocument = new KModel.model();
newDocument.findOneAndUpdate(
{ "_id": document._id}, // query
{ $setOnInsert: document}, // update or insert if does not exist
{
new: true, // return new doc if one is upserted
upsert: true // insert the document if it does not exist
},
function(err, object) {
if (err){
console.warn(err.message); // returns error if no matching object found
}
done(err);
});
}