Convert entity data so that it better fits Mongo's idiosyncrasies.
343351
private static function convertToMongo(array &$data)
    {
        // Move the ID field where Mongo expects it.
        if (isset($data['id'])) {
            // Create the _id field Mongo expects.
            $data['_id'] = $data['id'];
            // Remove the 'id' field from the data set that will be stored.
            unset($data['id']);
        }

        foreach ($data as $name => &$value) {
            // Ensure that all strings are UTF-8.
            if (is_string($value)) {
                // Convert all strings to UTF-8, otherwise Mongo complains.
                if (mb_detect_encoding($value) != 'UTF-8') {
                    $value = mb_convert_encoding($value, 'UTF-8');
                }
            } elseif ($value instanceof Entity) {
                // Only the presistable fields of Entities are kept.
                $value = $value->getFieldsData();
            } elseif (is_array($value)) {
                // The elements in an array are also checked in case they
                // contain sub-documents.
                self::convertToMongo($value);
            }
        }
    }
987065
def get_entities(self, data):
        """"""
        entities = self._filter_queryset('view_entity', data.entity_set.all())

        from .entity import EntitySerializer

        class EntityWithoutDataSerializer(WithoutDataSerializerMixin, EntitySerializer):
            """Entity without data field serializer."""

        return self._serialize_items(EntityWithoutDataSerializer, 'entities', entities)
799970
def from_mongo(cls, doc):
		""""""
		
		if doc is None:  # To support simplified iterative use, None should return None.
			return None
		
		if isinstance(doc, Document):  # No need to perform processing on existing Document instances.
			return doc
		
		if cls.__type_store__ and cls.__type_store__ in doc:  # Instantiate specific class mentioned in the data.
			cls = load(doc[cls.__type_store__], 'marrow.mongo.document')
		
		# Prepare a new instance in such a way that changes to the instance will be reflected in the originating doc.
		instance = cls(_prepare_defaults=False)  # Construct an instance, but delay default value processing.
		instance.__data__ = doc  # I am Popeye of Borg (pattern); you will be askimilgrated.
		instance._prepare_defaults()  # pylint:disable=protected-access -- deferred default value processing.
		
		return instance
754129
def to_object(record, attribute_map, stringify_keys = false)
      attributes = {}
      attribute_map.each do |map|
        map = map.inject({}) { |memo,(k,v)| memo[k.to_s] = v; memo} if stringify_keys
        if map["with"]
          as = deep_find(record, map["key"], map["nested_key"])
          values = []
          if as.is_a? Array
            values = as.map { |a| strip_refname( deep_find(a, map["with"]) ) }
          elsif as.is_a? Hash and as[ map["with"] ]
            values = as[ map["with"] ].is_a?(Array) ? as[ map["with"] ].map { |a| strip_refname(a) } : [ strip_refname(as[ map["with"] ]) ]
          end
          attributes[map["field"]] = values
        else
          attributes[map["field"]] = deep_find(record, map["key"], map["nested_key"])
        end
      end
      attributes
    end
660825
function mongoType(
  typeStr,
  options
) {
  const required = typeStr.match(/^(\S+)!$/);
  const list = typeStr.match(/^\[(\S+)]$/);

  if (required) {
    const innerType = required[1];
    if (_.includes(SCALARS, innerType)) {
      options.required = true;
    }
    return mongoType(innerType);
  } else if (list) {
    return [ mongoType(list[1]) ];
  }
  switch (typeStr) {
    case 'String':
      return String;
    case 'Int':
    case 'Float':
      return Number;
    case 'Boolean':
      return Boolean;
    case 'DateTime':
      return Date;
    case 'ID':
      return mongoose.Schema.Types.ObjectId;
    case 'JSON':
      return mongoose.Schema.Types.Mixed;
    default:
      throw new Error(typeStr);
  }
}
547358
def convertallfields(data, commdct, block=None):
    """"""
    # import pdbdb; pdb.set_trace()
    for key in list(data.dt.keys()):
        objs = data.dt[key]
        for i, obj in enumerate(objs):
            key_i = data.dtls.index(key)
            key_comm = commdct[key_i]
            try:
                inblock = block[key_i]
            except TypeError as e:
                inblock = None
            obj = convertfields(key_comm, obj, inblock)
            objs[i] = obj
603638
private synchronized void fetchMappingContextAndConversionService() {
		if(mappingContext == null) {
			MongoConverter mongoConverter = this.mongoTemplate.getConverter();
			mappingContext = mongoConverter.getMappingContext();
			conversionService = mongoConverter.getConversionService();

			MongoPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entityClass);
			MongoPersistentProperty idProperty = persistentEntity.getIdProperty();
			this.idKey = idProperty == null ? "_id" : idProperty.getName();
		}
	}
943865
function normalizeFields (options) {
  const fields = options.fields || options.outFields
  const idField = _.get(options, 'collection.metadata.idField')
  if (options.returnIdsOnly === true && idField) return [idField]
  else if (options.returnIdsOnly === true) return ['OBJECTID']
  if (fields === '*') return undefined
  if (typeof fields === 'string' || fields instanceof String) return fields.split(',')
  if (fields instanceof Array) return fields
  return undefined
}
922808
def convert(self, args, handler=None):
        """"""
        name = args
        field = attr = None
        opts = ()
        if isinstance(args, (list, tuple)):
            name, *opts = args
            if opts:
                attr = opts.pop()
            if opts:
                field = opts.pop()

        if not field and handler and handler.Schema:
            field = handler.Schema._declared_fields.get(attr or name) or \
                self.FILTER_CLASS.field_cls()
            field.attribute = field.attribute or attr or name
        return self.FILTER_CLASS(name, attr=attr, field=field, *opts)
650261
def to_mongo(self, disjunction=True):
        
        q = {}
        # add all the main clauses to `q`
        clauses = [e.expr for e in self._main]
        if clauses:
            if disjunction:
                if len(clauses) + len(self._where) > 1:
                    q['$or'] = clauses
                else:
                    # simplify 'or' of one thing
                    q.update(clauses[0])
            else:
                for c in clauses:
                    q.update(c)
        # add all the main2 clauses; these are not or'ed
        for c in (e.expr for e in self._main2):
            # add to existing stuff for the field
            for field in c:
                if field in q:
                    q[field].update(c[field])
                else:
                    q.update(c)
        # add where clauses, if any, to `q`
        if self._where:
            wsep = ' || ' if self._where[0].is_reversed else ' && '
            where_clause = wsep.join([w.expr for w in self._where])
            if disjunction:
                if not '$or' in q:
                    q['$or'] = []
                q['$or'].append({'$where': where_clause})
            else:
                q['$where'] = where_clause
        return q
1120739
def convert_association(self, association: Association) -> Entity:
        
        if "header" not in association or association["header"] == False:
            # print(json.dumps(association, indent=4))
            gpi_obj = {
                'id': association["subject"]["id"],
                'label': association["subject"]["label"],  # db_object_symbol,
                'full_name': association["subject"]["fullname"],  # db_object_name,
                'synonyms': association["subject"]["synonyms"],
                'type': association["subject"]["type"], #db_object_type,
                'parents': "", # GAF does not have this field, but it's optional in GPI
                'xrefs': "", # GAF does not have this field, but it's optional in GPI
                'taxon': {
                    'id': association["subject"]["taxon"]["id"]
                }
            }
            return Entity(gpi_obj)

        return None
630128
def extract_db_info(self, obj, keys):
        """"""

        objl = self.convert(obj)

        result = super(DataFrameType, self).extract_db_info(objl, keys)
        ext = self.datamodel.extractor_map['fits']
        if objl:
            with objl.open() as hdulist:
                for field in keys:
                    result[field] = ext.extract(field, hdulist)

                tags = result['tags']
                for field in self.tags_keys:
                    tags[field] = ext.extract(field, hdulist)

                return result
        else:
            return result
827680
def by_id(cls, oid):
        """"""
        if oid:
            d = cls.collection.find_one(ObjectId(oid))
            if d:
                return cls(**d)
561882
function normalizeEntity(entity) {
    if (entity !== null &&
            typeof entity !== 'undefined' &&
            typeof entity.getId === 'function') {
        return entity.getId();
    }
    return entity;
}
291751
def to_mongo(self):
        
        d = copy.copy(self._fields)
        for k, v in self._slices.items():
            d[k] = {'$slice': v}
        return d
1108932
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'entities' in _dict:
            args['entities'] = [
                QueryEntitiesResponseItem._from_dict(x)
                for x in (_dict.get('entities'))
            ]
        return cls(**args)
267007
def to_representation(self, value):
        """"""
        content_type = ContentType.objects.get_for_id(value)
        return "_".join(content_type.natural_key())