Download the PHP package jasny/db-mongo without Composer

On this page you can find all versions of the php package jasny/db-mongo. 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 db-mongo

Jasny DB Mongo

Build Status

Jasny DB Mongo adds OOP design patterns to PHP's MongoDB extension.

Jasny DB Mongo is not a DB abstraction layer, it extends the Mongo classes (except for Jasny\DB\Mongo\Cursor class, which incapsulates MongoDB\Driver\Cursor, but still allowing to call it's methods transparently). All of Mongo's classes, properties and methods are available and will work as described in the PHP manual.

Installation

Use composer to install Jasny Mongo DB.

Usage

It can be used in the same way as MongoDB extension, with a few improvements.

Init connection

When creating Database instance, we can use not only MongoDB\Driver\Manager as first parameter, but also an array of options, or even a uri connection string:

or

Or database name can be passed as second parameter, like it is required in MongoDB\Database.

Saving items

You can use collection save methods, defined in MongoDB\Collection. Unlike in old PHP Mongo extension, save method is removed from new extension. Our library implements it in Jasny\DB\Mongo\Collection class, as it is very handy.

So you can do:

After this $document will contain _id field.

If you use other saving methods like replaceOne, insertOne, insertMany, id field is not automatically attached to document, as we need to follow parent methods declaration, which does not allow this.

To assign created id to document, you can do:

That is automatically performed in some of our library classes, like Jasny\DB\Mongo\DataMapper or Jasny\DB\Mongo\Document.

Fetching from db

When using $cursor = $collection->find($filter) for fetching records, an instance of Jasny\DB\Mongo\Cursor is returned. It does not extend MongoDB\Driver\Cursor class, as all MongoDB\Driver classes are final. Instead it incapsulates it, implementing magical calling of all it's methods.

So the following check won't work:

But you still can do everything else:

`

or performing foreach iteration over cursor.

Cast fetched records

There is a base class we use for items, that are stored in DB. That's Jasny\DB\Entity, that is defined in Jasny DB repository.

Fetching db records using collection methods find and findOne can produce records of this class (or any of it subclasses you define).

To make use of that, you should obtain collection instance in the following way:

Casting to Entity class is performed by our framework, without use of MongoDB typeMap functionality, because casting can be pretty complex.

Than in the following case:

$record is an instance of Jasny\DB\Entity.

In the following case:

to obtain casted records, you should either iterate over $cursor using foreach, or use $cursor->toArrayCast() method, implemented by our framework. If you use native $cursor->toArray() method, implemented by MongoDB\Driver\Cursor, records use casting defined in collection's typeMap option. By default we set this option to use casting to array.


All versions of db-mongo with dependencies

PHP Build Version
Package Version
Requires ext-mongodb Version ^1.4.0
php Version >=7.0
jasny/db Version ^2.4.5
doctrine/inflector Version ^1.0
mongodb/mongodb Version ^1.3
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 jasny/db-mongo contains the following files

Loading the files please wait ....