Download the PHP package mongodb/symfony-bundle without Composer

On this page you can find all versions of the php package mongodb/symfony-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package symfony-bundle

Symfony Bundle for MongoDB (EXPERIMENTAL)

This bundle provides integration of the MongoDB library into Symfony. It is designed as a lightweight alternative to the Doctrine MongoDB ODM, providing only an integration to interact with MongoDB without providing all features of an ODM.

Installation

Install the bundle with composer:

If you have symfony/flex installed, the bundle is automatically enabled. Otherwise, you need to enable it manually by adding it to the bundles.php file:

Configuration

Configuration is done in the config/packages/mongodb.yaml file. To get started, you need to configure at least one client:

The id is used to reference the client in the service container. The uri is the connection string to connect to. For security reasons, it is recommended to read this value from your local environment and referencing it through an environment variable in the container:

You can also specify additional options for the client:

The uri_options and driver_options are passed directly to the underlying MongoDB driver. See the documentation for available options.

If you want to configure multiple clients, you can do so by adding additional clients to the configuration:

[!NOTE] If you add multiple clients, you need to specify the default_client option to specify which client should be used as default!

Client Usage

For each client, a service is registered in the container with the mongodb.client.{id} service id.

[!NOTE] The MongoDB driver only establishes a connection to MongoDB when it is actually needed, so a client can be injected into services without causing network traffic.

With autowiring enabled, you can inject the client into your services like this:

If you register multiple clients, you can autowire them by using the client name with a Client suffix as parameter name:

or by using the #[AutowireClient] attribute:

Database Usage

The client service provides access to databases and collections. You can access a database by calling the selectDatabase method, passing the database name and potential options:

An alternative to this is using the #[AutowireDatabase] attribute, referencing the database name:

If you don't specify a database name in the attribute, the default database name (specified in the default_database configuration option) will be used. If you did not define a default database, the database name has to be specified in the attribute.

If you have more than one client defined, you can also reference the client:

Collection Usage

To inject a collection, you can either call the selectCollection method on a Client or Database instance. For convenience, the #[AutowireCollection] attribute provides a quicker alternative:

You can also omit the collection option if the property name matches the collection name. In the following example the collection name is myCollection, inferred from the property name:

If you have more than one client defined, you can also reference the client:

By specifiying the default_database option in the configuration, you can omit the database option in the AutowireCollection attribute:

Specifying options

When using the AutowireDatabase or AutowireCollection attributes, you can specify additional options for the resulting instances. You can pass the following options: || Option || Accepted type || | codec | DocumentCodec instance | | typeMap| array containing type map information | | readPreference | MongoDB\Driver\ReadPreference instance | | writeConcern | MongoDB\Driver\writeConcern instance | | readConcern | MongoDB\Driver\ReadConcern instance |

In addition to passing an instance, you can also pass a service reference by specifying a string for the given option:


All versions of symfony-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
mongodb/mongodb Version ^1.17
symfony/config Version ^6.3 || ^7.0
symfony/console Version ^6.3 || ^7.0
symfony/dependency-injection Version ^6.3.5 || ^7.0
symfony/http-kernel Version ^6.3.5 || ^7.0
symfony/runtime Version ^6.3 || ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mongodb/symfony-bundle contains the following files

Loading the files please wait ....