Download the PHP package jpc/mongodb-odm without Composer

On this page you can find all versions of the php package jpc/mongodb-odm. 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 mongodb-odm

MongoDB-ODM

JPC\MongoDB-ODM is a smart MongoDB-PHP mappers. It lets you to get your Object in PHP mapped into document in MongoDB. This library support last driver of mongodb available here.

See 'doc' folder for more details.

Install

Install With Composer

In your console terminal :

Or in your :

Create Mapping Class

Your class

To work with MongoDB-ODM, you need to see your class like a mongoDb document and define what you need :

You can create a simple object like this

Ok, you have your class. Now you have to tell to MongoDB-ODM which property match which field, and in which collection document are (and will be) stored.

Mapping

For this, MongoDB-ODM use annotations. There is basics annotations to make a mapping that are in JPC\MongoDB\ODM\Annotations\Mapping:

Advanced Mapping

Ok, you have a simple document but it still to miss something... Maybe things like embedded documents. Don't worry, MongoDB-ODM support them!

Create your embedded class like the previous one :

You can now use two annotations to add embedded in the previous class :

Modify the class MyDoc like this :

Get document

Get a document manager

You can easily create a document manager with the factory available in the library.

The factory has a method createDocumentManager that take mongo uri in first argument, and database name in second.

Now, create a document manager :

Get the repository

Now, you need to get the repository. Repository will allow you to get document from MongoDB.

To get Repository use the function getRepository method of document manager.

This is the method :

If $collection is null, MongoDB-ODM take the collection setted in the Document annotation of the model

In our case (With model configured in 2-create-mapping-class) :

You can now simply find a document by using one of this functions of repository (See method declaration for more infos about methods):

Example :

Insert, update or remove a document

Insert a document

First, you have to create your object and insert data inside it :

Good! Now we want to store it in database. For this, you have to tell to MongoDB-ODM that your object have to be managed by him. By manage i mean that MongoDB-ODM will see if it has to insert, update or remove your object.

So, to do this, you need to persist your object.

Here is the persist function of document manager :

For our object :

Next step is tell to MongoDB-ODM that it has to save all changes of all managed object. For this, there is a function called flush, just call it.

Check your mongoDb collection, if it's empty, you probably make a mistake :confused:

Update a document

Imagine that you have a lot of document in your collection and you want to update some of them.

First, you have to get the document that you want, like this :

Note : If you have inserted a document with persist and flush, it is ready for update, you don't need to get it from repository again

Now make some modification on them :

This is really nice modification :wink:

Now you just have to flush.

Note : Finded object from repositories are already persisted, you don't have to persist again

Remove a document

Removing is easy like updating

Get your document from repository and just say to document manager that it has to remove them and flush:

Additional information

Advantage of using update with MongoDB-ODM

Advantage of using MongoDB-ODM for update is that it will just update modified field and not the whole object.

Unpersist

If you make some modification on persisted object in your code and you don't want to store changes at next flush, you can unpersist it with the unpersist function :

If you want to unpersist all objects, use clear

GridFS Document

Create mapping for GridFS document

Your class need to inherit class JPC\MongoDB\ODM\GridFS\Document. This class define all default field of a gridFS document like md5, filename, etc... See this class for more details.

To add metadata to your doc, you need to use the Metadata annotations.

Here is an example :

Note that class Document annotation is provided from GFS and not by ODM namespace

Insert your document

Insert a document in gridFS is like insert a document in basic mongoDB collection.

Here's a full example :

Collections Options

Collections options

When you create a model, you can specify more information on the Document annotion :

And you can set ReadConcern, ReadPreference, TypeMap and WriteConcern with the Option annotation (Don't forget the use) :

Events

Availabe events

Name Description
PostLoad Called after the document was loaded from database
PrePersist Called before persist executed
PostPersist Called after persist executed
PreFlush Called before flush executed (Even if document has not changed)
PostFlush Called after flush executed (Even if document has not changed)
PreInsert Called before document is inserted in database
PostInsert Called after document is inserted in database
PreUpdate Called before document is updated in database
PostUpdate Called after document is updated in database
PreDelete Called after document is updated in database
PostDelete Called after document is updated in database

How to use

To add event on your model class, you need to tell ODM that you want to use some event with HasLifecycleCallbacks annotation

You can now add some methods with events annotations


All versions of mongodb-odm with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5
doctrine/annotations Version ^1.4|^1.6
doctrine/cache Version ^1.6|^1.7|^1.8
mongodb/mongodb Version ^1.4
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 jpc/mongodb-odm contains the following files

Loading the files please wait ....