Ensures the proper fields are indexed
162014
def _create_indexes(self):
        """"""
        # WARNING: The collection will be locked during the index
        # creation. If the collection has a large number of
        # documents in it, the operation can take a long time.

        # TODO: The creation of indexes can be moved to a Django
        # management command or equivalent. There is also an option to
        # run the indexing on the background, without locking.
        self.collection.ensure_index([('time', pymongo.DESCENDING)])
        self.collection.ensure_index('name')
1162456
def prepare_fields(fields):
    
    def process_item(value):
        if not isinstance(value, NUMERIC_TYPES):
            if isinstance(value, six.string_types):
                # encode utf-8 to unicode, if necessary
                return force_text(value)
            else:
                if isinstance(value, dict):
                    return prepare_fields(value)
                elif isinstance(value, list):
                    return list(map(process_item, value))

                return six.text_type(value)
        return value

    return dict((key, process_item(value))
                for key, value
                in fields.items())
1200329
private AssignmentField selectField(AssignmentField[] fields, int index)
   {
      if (index < 1 || index > fields.length)
      {
         throw new IllegalArgumentException(index + " is not a valid field index");
      }
      return (fields[index - 1]);
   }
1347451
def iter_valid_fields(meta):
    """"""

    # fetch field configuration and always add the id_field as exclude
    meta_fields = getattr(meta, 'fields', ())
    meta_exclude = getattr(meta, 'exclude', ())
    meta_exclude += (meta.document._meta.get('id_field'),)

    # walk through meta_fields or through the document fields to keep
    # meta_fields order in the form
    if meta_fields:
        for field_name in meta_fields:
            field = meta.document._fields.get(field_name)
            if field:
                yield (field_name, field)
    else:
        for field_name, field in meta.document._fields.iteritems():
            # skip excluded fields
            if field_name not in meta_exclude:
                yield (field_name, field)
1012075
def perform_index_validation(self, data):
        
        # Build a list of dict containing query values for each unique index.
        index_data = []
        for columns, unique in self.instance._meta.indexes:
            if not unique:
                continue
            index_data.append({col: data.get(col, None) for col in columns})

        # Then query for each unique index to see if the value is unique.
        for index in index_data:
            query = self.instance.filter(**index)
            # If we have a primary key, need to exclude the current record from the check.
            if self.pk_field and self.pk_value:
                query = query.where(~(self.pk_field == self.pk_value))
            if query.count():
                err = ValidationError('index', fields=str.join(', ', index.keys()))
                for col in index.keys():
                    self.add_error(col, err)
466097
private function ensureFilesIndex()
    {
        foreach ($this->filesCollection->listIndexes() as $index) {
            if ($index->getKey() === ['filename' => 1, 'uploadDate' => 1]) {
                return;
            }
        }

        $this->filesCollection->createIndex(['filename' => 1, 'uploadDate' => 1]);
    }
315427
def _clean_schema_fields(self, fields):
        """"""
        fields_sorted = sorted(fields, key=lambda field: field["name"])
        # Ignore mode and description when comparing schemas.
        return [
            {"name": field["name"], "type": field["type"]}
            for field in fields_sorted
        ]
272383
def fix_additional_fields(data):
        """"""
        result = dict()
        for key, value in data.items():
            if isinstance(value, dict):
                result.update(KserSpan.to_flat_dict(key, value))
            else:
                result[key] = value
        return result
1119884
public void checkFieldsCompatible(final String... fields) {
        final Set<String> indexFields = Sets.newHashSet(index.getDefinition().getFields());
        final Joiner joiner = Joiner.on(",");
        check(indexFields.equals(Sets.newHashSet(fields)),
                "Existing index '%s' (class '%s') fields '%s' are different from '%s'.",
                index.getName(), index.getDefinition().getClassName(), joiner.join(indexFields), joiner.join(fields));
    }
313737
function findMatchingIndexes(selector, userFields, sortOrder, indexes) {

  return indexes.reduce(function (res, index) {
    var indexMatches = checkIndexMatches(index, sortOrder, userFields, selector);
    if (indexMatches) {
      res.push(index);
    }
    return res;
  }, []);
}
1115155
private function ensureFileIndexes()
    {
        $indexKey = ['filename' => 1, 'uploadDate' => 1];
        foreach ($this->listIndexes() as $index) {
            if ($index['key'] === $indexKey) {
                return;
            }
        }

        $this->createIndex($indexKey);
    }
784047
function getIndexes(done, results) {
  var client = results.client;
  var ns = mongodbNS(results.namespace);
  client
    .db(ns.database)
    .collection(ns.collection)
    .indexes(function(err, indexes) {
      if (err) {
        done(err);
      }
      // add ns field to each index
      _.each(indexes, function(idx) {
        idx.ns = ns.ns;
      });
      done(null, indexes);
    });
}
1318772
def ensure_indexes(self):
        """"""
        for collection_name in INDEXES:
            existing_indexes = self.indexes(collection_name)
            indexes = INDEXES[collection_name]
            for index in indexes:
                index_name = index.document.get('name')
                if index_name in existing_indexes:
                    logger.debug("Index exists: %s" % index_name)
                    self.db[collection_name].drop_index(index_name)
            logger.info("creating indexes for collection {0}: {1}".format(
                collection_name,
                ', '.join([index.document.get('name') for index in indexes]),
                )
            )
            self.db[collection_name].create_indexes(indexes)
644950
def index_by(self, field):
        
        values = self[field].unique()
        results = {}
        for value in values:
            results[value] = self.model_class(**self[self[field] == value].iloc[0])
        return results
416812
def ensure_index(self, key, sparse=False):
        
        self.create_index(key, reindex=False, sparse=False)
38348
private function ensureChunkIndexes()
    {
        $chunkCollection = $this->getChunkCollection();
        $indexKey = ['files_id' => 1, 'n' => 1];
        foreach ($chunkCollection->listIndexes() as $index) {
            if (!empty($index['unique']) && $index['key'] === $indexKey) {
                return;
            }
        }
        $chunkCollection->createIndex($indexKey, ['unique' => true]);
    }
440704
function syncFieldsBetweenTabs( currentPageId ) {
		var sourceIndex, targetIndex, sourceField, targetField;

		sourceIndex = currentPageId === 'find' ? 1 : 0;
		targetIndex = 1 - sourceIndex;
		var i,
			l = fieldsMapping.length;
		for ( i = 0; i < l; i++ ) {
			sourceField = this.getContentElement( pages[ sourceIndex ], fieldsMapping[ i ][ sourceIndex ] );
			targetField = this.getContentElement( pages[ targetIndex ], fieldsMapping[ i ][ targetIndex ] );

			targetField.setValue( sourceField.getValue() );
		}
	}