示例#1
0
文件: helpers.js 项目: zjjw/thredd
// caution, this will mutate the array of records!
function recordsToObjs (list) {
  return listify(list).map(function (record) {
    record.id = record._id.toString();
    delete record._id;
    return record;
  });
}
示例#2
0
文件: helpers.js 项目: zjjw/thredd
function findByField (field, ids, coll) {
  var query = {};
  query[field] = { $in: listify(ids) };
  return coll.find(query).then(function (results) {
    return recordsToObjs(results);
  });
}
示例#3
0
文件: helpers.js 项目: zjjw/thredd
function validateAndSave (modelList, schema, coll) {
  modelList = listify(modelList).map(function (model) {
    // will throw when a validation fails
    return validate(model, schema, coll);
  });
  return coll.insert(modelList).then(function (success) {
    return recordsToObjs(success);
  });
}
示例#4
0
文件: helpers.js 项目: zjjw/thredd
function objectIds (id, coll) {
  return listify(id).map(function (id) {
    return coll.id(id);
  });
}