Download the PHP package martynbiz/php-mongo without Composer

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

Installation

Install with composer

Getting started

Create connection

Create model

Create models by extending the Mongo class, be sure to define $collection and $whitelist:

Create multiple connections

If only using a single database, this is not neccessary. However, if you need to connect to multiple databases, give a unique name to each connection:

Also, remember to declare which $conn in the model:

Queries

Find by mongo query

Find one by mongo query

Finding by object

Model instances can also be passed, the find method will convert it to DBRef internally (e.g. 'friend' => $friend will do the same as 'friend' => $friend->getDBRef())

Getting and setting values

Inserting

Save method is used on an instantiated object of the model class. It can be called after assigning values to properties, or by passing name/values as arguments. Note: when passing name/values, values will be whitelisted

Create method doesn't require an instance, by will accept name\values upon which it will insert into the collection. It will return an instance of the created document. Note: when passing name/values, values will be whitelisted

Factory method doesn't actually insert, but will generate an instance with values. It can then be altered and inserted with it's save method:

Although having multiple methods may seem a little much, it does give the option to keep you code tidy and more flexible for mocking methods during testing.

Push

Note: push with $each is the default behaviour here, although this can be overridden with 'each'=>false in the options array (see below)

Deleting

An instance can delete itself from the database with the delete method:

To delete multiple documents from a collection by query, use the remove method:

Convert to array

Validation

Before saving to the database, the validate method is called. If it returns false, the data will not be saved.

The following example uses martynbiz/php-validator library here.

Custom Getter/ Setter

To automatically convert values when getting, you can define custom methods to automatically convert the value of a property. This may be useful when formatting strings such as dates to human readable.

TODO


All versions of php-mongo with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.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 martynbiz/php-mongo contains the following files

Loading the files please wait ....