Call the pymongo method ``ensure_index`` on the passed collection.

            :param collection: the ``pymongo`` collection to ensure this index \
                    is on
489072
def ensure(self, collection):
        ''' 
        '''
        components = []
        for c in self.components:
            if isinstance(c[0], Field):
                c = (c[0].db_field, c[1])
            components.append(c)

        extras = {}
        if self.__min is not None:
            extras['min'] = self.__min
        if self.__max is not None:
            extras['max'] = self.__max
        if self.__bucket_size is not None:
            extras['bucket_size'] = self.__bucket_size
        if self.__expire_after is not None:
            extras['expireAfterSeconds'] = self.__expire_after

        collection.ensure_index(components, unique=self.__unique,
            drop_dups=self.__drop_dups, **extras)
        return self
1236797
def create_index(self, collection, index_name, **kwargs):
        """"""
        try:
            self.connection[collection].create_index(index_name, **kwargs)
        except Exception as exc:
            LOG.warn("Error tuning mongodb database: %s", exc)
438916
public function updateCollection(Collection $collection): void
    {
        $query = $this->connection->createQueryBuilder();
        $query
            ->update('ngbm_collection')
            ->set('start', ':start')
            ->set('length', ':length')
            ->set('translatable', ':translatable')
            ->set('main_locale', ':main_locale')
            ->set('always_available', ':always_available')
            ->where(
                $query->expr()->eq('id', ':id')
            )
            ->setParameter('id', $collection->id, Type::INTEGER)
            ->setParameter('start', $collection->offset, Type::INTEGER)
            ->setParameter('length', $collection->limit, Type::INTEGER)
            ->setParameter('translatable', $collection->isTranslatable, Type::BOOLEAN)
            ->setParameter('main_locale', $collection->mainLocale, Type::STRING)
            ->setParameter('always_available', $collection->alwaysAvailable, Type::BOOLEAN);

        $this->applyStatusCondition($query, $collection->status);

        $query->execute();
    }
1323475
def ensure_table(self, cls):
        """"""
        coll_name = cls.get_table_name()
        try:
            db = self.mongo_client.get_default_database()
            db.create_collection(coll_name)
        except CollectionInvalid:
            pass  # Expected if collection already exists

        # Make sure we have indexes
        coll = self.get_collection(coll_name)
        for idx_name in cls.index_names():
            coll.ensure_index(idx_name)
555720
public function setCollection($collection)
    {
        if (!$this->loaded) {
            $this->load();
        }

        $this->collectionInfo->setCollection($collection);
        return $this;
    }
354205
def get_collection(self, **kwargs):
        
        from pymongo import MongoClient

        if self.host and self.port:
            client = MongoClient(host=config.host, port=config.port)
        else:
            client = MongoClient()
        db = client[self.dbname]

        # Authenticate if needed
        if self.user and self.password:
            db.autenticate(self.user, password=self.password)

        return db[self.collection]
794132
def _ensure_index_cache(self, db_uri, db_name, collection_name):
        """"""
        if not self._check_indexes or db_uri is None:
            return {'indexes': None}
        if db_name not in self.get_cache():
            self._internal_map[db_name] = {}
        if collection_name not in self._internal_map[db_name]:
            indexes = []
            try:
                if self._index_cache_connection is None:
                    self._index_cache_connection = pymongo.MongoClient(db_uri,
                                                                       document_class=OrderedDict,
                                                                       read_preference=pymongo.ReadPreference.PRIMARY_PREFERRED)

                db = self._index_cache_connection[db_name]
                indexes = db[collection_name].index_information()
            except:
                warning = 'Warning: unable to connect to ' + db_uri + "\n"
            else:
                internal_map_entry = {'indexes': indexes}
                self.get_cache()[db_name][collection_name] = internal_map_entry
        return self.get_cache()[db_name][collection_name]
904499
def dispatch(self, collection, **kwargs):
        
        for inventory, method in self.methods[::-1]:
            if method(collection, **kwargs) is True:
                collection.parent = self.collection.children[inventory]
                return
        raise UndispatchedTextError("CapitainsCtsText not dispatched %s" % collection.id)
73405
function(ferret, collection_name, callback) {
    _ready(ferret, function(err) {
        if (err) {
            process.nextTick(function() {
                callback(err)  
            })
        } else {
            if (ferret._collections[collection_name]) {
                process.nextTick(function() {
                    callback(null, ferret._collections[collection_name])
                })
            } else {
                ferret._db.collection(collection_name, function(err, collection){
                    if (!err) { ferret._collections[collection_name] = collection }
                    callback(err, collection)
                })
            }
        }
    })
}
1059374
protected void initCollection() {
        boolean collectionExists = MongoUtils.collectionExists(getDatabase(), getCollectionName());
        if (!collectionExists) {
            LOGGER.info("Creating collection [" + getCollectionName() + "]...");
            getDatabase().createCollection(getCollectionName());
            MongoCollection<?> collection = getCollection();

            LOGGER.info("Creating index for field [" + getCollectionName() + "."
                    + MongodbQueue.COLLECTION_FIELD_ID + "]...");
            collection.createIndex(new Document().append(MongodbQueue.COLLECTION_FIELD_ID, 1),
                    new IndexOptions().unique(true));

            LOGGER.info("Creating index for field [" + getCollectionName() + "."
                    + MongodbQueue.COLLECTION_FIELD_EPHEMERAL_KEY + "]...");
            collection.createIndex(
                    new Document().append(MongodbQueue.COLLECTION_FIELD_EPHEMERAL_KEY, 1),
                    new IndexOptions());

            LOGGER.info("Creating index for field [" + getCollectionName() + "."
                    + MongodbQueue.COLLECTION_FIELD_QUEUE_TIME + "]...");
            collection.createIndex(
                    new Document().append(MongodbQueue.COLLECTION_FIELD_QUEUE_TIME, 1),
                    new IndexOptions());

            LOGGER.info("Creating index for field [" + getCollectionName() + "."
                    + MongodbQueue.COLLECTION_FIELD_TIME + "]...");
            collection.createIndex(new Document().append(MongodbQueue.COLLECTION_FIELD_TIME, 1),
                    new IndexOptions());

        }
    }
479816
def _get_collection(self, collection_name):
        
        try:
            return self._database[collection_name]
        except InvalidName as ex:
            raise DataSourceError("Cannot access MongoDB collection %s!"
                                  % collection_name) from ex
        except Exception as ex:
            raise DataSourceError("Unexpected error when accessing MongoDB"
                                  "collection %s!"
                                  % collection_name) from ex
684139
public static void assertSingleElement(final Collection<?> collection, final StatusType status) {
		RESTAssert.assertNotNull(collection, status);
		RESTAssert.assertTrue(collection.size() == 1, status);
	}
84094
function (err, collection) {
                if (err) {
                    return callback(err);
                }

                // ensure that the collection option is present before starting a run
                if (!_.isObject(collection)) {
                    return callback(new Error(COLLECTION_LOAD_ERROR_MESSAGE));
                }

                // ensure that the collection reference is an SDK instance
                // @todo - should this be handled by config loaders?
                collection = new Collection(Collection.isCollection(collection) ?
                    // if the option contain an instance of collection, we simply clone it for future use
                    // create a collection in case it is not one. user can send v2 JSON as a source and that will be
                    // converted to a collection
                    collection.toJSON() : collection);

                callback(null, collection);
            }
24167
function(collection, options, cb) {
    this.store().setItem(
      options.indexKey,
      JSON.stringify([]),
      function(err, res) {
        cb(err, [], res);
      }
    );
  }
1004308
def check
      return @checked if @checked # If already checked, it's alright

      raise MissingFixtureError, "No fixture has been loaded, nothing to check" unless @data
      raise MissingConnectionError, "No connection has been provided, impossible to check" unless @connection
      
      @data.each_key do |collection|
        raise CollectionsNotEmptyError, "The collection '#{collection}' is not empty, all collections should be empty prior to testing" if @connection[collection].count != 0
      end
      return @checked = true
    end
1071200
def post_collection(self, collection, body):
        
        assert isinstance(body, (list)), "POST requires body to be a list"
        assert collection.startswith('/'), "Collections must start with /"
        uri = self.uri + '/v1' + collection
        return self.service._post(uri, body)
1365490
def post_resource(collection):
    
    cls = endpoint_class(collection)
    resource = cls()
    resource.from_dict(get_resource_data(request))

    _validate(cls, request.method, resource)

    _perform_database_action('add', resource)
    return resource_created_response(resource)