Download the PHP package jenssegers/mongodb-lite without Composer

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

Laravel MongoDB Lite

Build Status Coverage Status

The lite version of https://github.com/jenssegers/laravel-mongodb

The difference between the full version and this lite version is as following:

This lite version returns the native PHP MongoDB collection object instead of hiding them behind the query builder. This can be useful for people who want to do advanced MongoDB stuff using the original methods.

It also ships with a basic Eloquent-like model for extra flexibility. More information about this model can be found below.

Installation

Install using composer:

composer require jenssegers/mongodb-lite

Add the service provider in app/config/app.php:

'Jenssegers\Mongodb\Lite\MongodbServiceProvider',

Configuration

Change your default database connection name in app/config/database.php:

'default' => 'mongodb',

And add a new mongodb connection:

'mongodb' => array(
    'driver'   => 'mongodb',
    'host'     => 'localhost',
    'port'     => 27017,
    'username' => 'username',
    'password' => 'password',
    'database' => 'database'
),

Getting a Collection

Once your configuration is in place you can access your collections like this:

DB::collection('users');

This returns the MongoCollection object associated with the 'mongodb' connection item. If you want to use a different connection use:

DB::connection('mongodb2')->collection('users');
// A MongoCollection object

Because this returns the native MongoCollection object you can use all of the standard methods:

$users = DB::collection('users')->find();
$count = DB::collection('users')->count();
$user = DB::collection('users')->findOne(array('name' => 'John Doe'));

Model

A model offers a more flexible way to access a collection.

use Jenssegers\MongodbLite\Model as Eloquent;

class User extends Eloquent {

    protected $collection = 'users';

}

You can use all standard MongoCollection operations here as well:

$users = User::find();

Collections

All multi-result sets returned by the model return an Laravel Collection object. This object implements the IteratorAggregate PHP interface so it can be iterated over like an array. However, this object also has a variety of other helpful methods for working with result sets. More information about this at http://laravel.com/docs/eloquent#collections

$users = User::all();
// Will return a collection of User objects

// Do laravel-collection operations
$user = $users->first();
$count = $users->count();

Accessors & Mutators

Because model objects are returned, you can still define custom methods and use accessors and mutators. More information about this at http://laravel.com/docs/eloquent#accessors-and-mutators

use Jenssegers\MongodbLite\Model as Eloquent;

class User extends Eloquent {

    protected $collection = 'users';

    // Accessor
    public function getAvatarAttribute()
    {
        $hash = md5($this->attributes['email']);
        return "http://www.gravatar.com/avatar/$hash";
    }

    // Mutator
    public function setPasswordAttribute($value)
    {
        $this->attributes['password'] = crypt($value);
    }
}

Which can then be used like this:

$user = User::findOne(array('_id' => new MongoId('47cc67093475061e3d9536d2')));
echo $user->avatar;

Insert, Update, Delete

To create a new record in the database from a model, simply create a new model instance and call the save method.

$user = new User;
$user->name = 'John Doe';
$user->save();

To update a model, you may retrieve it, change an attribute, and use the save method:

$user->age = 35;
$user->save();

You can create a new model using:

$user = User::create(array('name' => 'John'));

To delete a model, simply call the delete method on the instance:

$user->delete();

Converting To Arrays / JSON

You can convert a model or a collection of models to array or json just like in Eloquent:

$user->toArray();
$user->toJson();

All versions of mongodb-lite with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
illuminate/support Version 4.2.*
illuminate/database Version 4.2.*
jenssegers/model Version *
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 jenssegers/mongodb-lite contains the following files

Loading the files please wait ....