How to use mpath - 10 common examples

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 wobscale / EuIrcBot / node-module-manager.js View on Github external
me.getModuleName = function (mpath) {
  let m;
  const stats = fs.statSync(mpath);
  try {
    m = require(mpath).name;
    if (m) return m;
  } catch (ex) {
    /* not a warning yet. Eventually maybe */
  }
  if (stats.isDirectory()) {
    try {
      m = JSON.parse(fs.readFileSync(path.join(mpath, 'package.json'))).name;
      if (m) return m;
    } catch (ex) {
      log.warn(ex, 'invalid package.json for %s', mpath);
    }
  }
  return mpath;
};
github GilbertGobbels / GAwesomeBot / Database / Query.js View on Github external
prop (path) {
		try {
			if (path === "..") {
				const index = this.parsed.lastIndexOf(".");
				this.parsed = this.parsed.substring(0, index);
				this._current = this.parsed === "" ? this._doc._doc : mpath.get(this.parsed, this._doc._doc);

				this._shiftSchema(this.parsed, true);

				return this;
			}

			this.parsed += this._parseForString(path);
			this._current = mpath.get(this.parsed, this._doc._doc);
			this._shiftSchema(path);
			return this;
		} catch (err) {
			throw new GABError("GADRIVER_ERROR", { err }, `Could not parse Query: ${err.message}`);
		}
	}
github dinubs / jam-api / node_modules / mongoose / lib / utils.js View on Github external
exports.getValue = function(path, obj, map) {
  return mpath.get(path, obj, '_doc', map);
};
github cvent / lounge / lib / cbdocument.utils.js View on Github external
const indexType = indexes[v].indexType

      let value = null
      if (indexes[v].compound) {
        value = _.map(path, p => processValue(mpath.get(p, data)))
        value = expandValues(value)
        value = _.compact(value)

        const containsNested = _.some(value, _.isArray)
        if (containsNested) {
          value = _.map(value, v => v.join('_'))
        } else {
          value = value.join('_')
        }
      } else {
        value = processValue(mpath.get(path, data))
      }

      ret[name] = {
        path,
        value,
        name,
        indexType
      }
    }
  }

  return ret
}
github legomushroom / iconmelon / node_modules / mongoose / lib / utils.js View on Github external
exports.getValue = function (path, obj, map) {
  return mpath.get(path, obj, '_doc', map);
}
github joshlobaptista / Barista-Fullstack / node_modules / mongoose / lib / utils.js View on Github external
exports.getValue = function(path, obj, map) {
  return mpath.get(path, obj, '_doc', map);
};
github KIDx / GzhuOJ / node_modules / mongoose / lib / utils.js View on Github external
exports.getValue = function (path, obj, map) {
  return mpath.get(path, obj, '_doc', map);
}

mpath

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

MIT
Latest version published 3 years ago

Package Health Score

68 / 100
Full package analysis