How to use the mpath.set function in mpath

To help you get started, we’ve selected a few mpath examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github misspink1011 / News-Manager / web_server / server / node_modules / mongoose / lib / model.js View on Github external
}

    if (o.isVirtual && !o.justOne && !Array.isArray(rawIds[i])) {
      if (rawIds[i] == null) {
        rawIds[i] = [];
      } else {
        rawIds[i] = [rawIds[i]];
      }
    } else if (o.isVirtual && o.justOne && Array.isArray(rawIds[i])) {
      rawIds[i] = rawIds[i][0];
    }

    if (o.isVirtual && docs[i].constructor.name === 'model') {
      // If virtual populate and doc is already init-ed, need to walk through
      // the actual doc to set rather than setting `_doc` directly
      mpath.set(o.path, rawIds[i], docs[i]);
    } else {
      var parts = o.path.split('.');
      var cur = docs[i];
      for (var j = 0; j < parts.length - 1; ++j) {
        if (cur[parts[j]] == null) {
          cur[parts[j]] = {};
        }
        cur = cur[parts[j]];
      }
      if (docs[i].$__) {
        docs[i].populated(o.path, o.allIds[i], o.allOptions);
      }
      utils.setValue(o.path, rawIds[i], docs[i], setValue);
    }
  }
}
github didinj / node-express-mongoose-passport-jwt-rest-api-auth / node_modules / mongoose / lib / document.js View on Github external
return this;
  }

  let schema;
  const parts = path.split('.');

  if (pathType === 'adhocOrUndefined' && strict) {
    // check for roots that are Mixed types
    let mixed;

    for (i = 0; i < parts.length; ++i) {
      const subpath = parts.slice(0, i + 1).join('.');

      // If path is underneath a virtual, bypass everything and just set it.
      if (i + 1 < parts.length && this.schema.pathType(subpath) === 'virtual') {
        mpath.set(path, val, this);
        return this;
      }

      schema = this.schema.path(subpath);
      if (schema == null) {
        continue;
      }

      if (schema instanceof MixedSchema) {
        // allow changes to sub paths of mixed types
        mixed = true;
        break;
      }
    }

    if (schema == null) {
github sx1989827 / DOClever / Server / node_modules / mongoose / lib / model.js View on Github external
!o.originalModel.schema._getVirtual(o.path)) {
      continue;
    }

    if (o.isVirtual && !o.justOne && !Array.isArray(rawIds[i])) {
      if (rawIds[i] == null) {
        rawIds[i] = [];
      } else {
        rawIds[i] = [rawIds[i]];
      }
    }

    if (o.isVirtual && docs[i].constructor.name === 'model') {
      // If virtual populate and doc is already init-ed, need to walk through
      // the actual doc to set rather than setting `_doc` directly
      mpath.set(o.path, rawIds[i], docs[i]);
    } else {
      var parts = o.path.split('.');
      var cur = docs[i];
      for (var j = 0; j < parts.length - 1; ++j) {
        if (cur[parts[j]] == null) {
          cur[parts[j]] = {};
        }
        cur = cur[parts[j]];
      }
      if (docs[i].$__) {
        docs[i].populated(o.path, o.allIds[i], o.allOptions);
      }
      utils.setValue(o.path, rawIds[i], docs[i], setValue);
    }
  }
}
github cvent / lounge / lib / cbdocument.js View on Github external
}, err => {
        if (!err) {
          mpath.set(path, idArray, this)
        }
        return fn(err)
      })
    }
github sparklr / sparklr / backend / node_modules / mongoose / lib / utils.js View on Github external
exports.setValue = function (path, val, obj, map) {
  mpath.set(path, val, obj, '_doc', map);
}
github assemblee-virtuelle / Semantic-Bus / core / node_modules / mongoose / lib / utils.js View on Github external
exports.setValue = function(path, val, obj, map, _copying) {
  mpath.set(path, val, obj, '_doc', map, _copying);
};
github dinubs / jam-api / node_modules / mongoose / lib / utils.js View on Github external
exports.setValue = function(path, val, obj, map) {
  mpath.set(path, val, obj, '_doc', map);
};
github kiril-me / cassandrom / lib / utils.js View on Github external
exports.setValue = function(path, val, obj, map) {
  mpath.set(path, val, obj, '_doc', map);
};
github sx1989827 / DOClever / node_modules / mongoose / lib / utils.js View on Github external
exports.setValue = function(path, val, obj, map, _copying) {
  mpath.set(path, val, obj, '_doc', map, _copying);
};

mpath

{G,S}et object values using MongoDB-like path notation

MIT
Latest version published 2 years ago

Package Health Score

68 / 100
Full package analysis