Giter Site home page Giter Site logo

mongo-lite's Introduction

MongoLite

Schemaless database on top of SqLite

Sample Usage

$client     = new MongoLite\Client(PATH_TO_WRITABLE_FOLDER);
$database   = $client->testdb;
$collection = $database->products;

$entry = ["name"=>"Super cool Product", "price"=>20];

$collection->insert($entry);

$products = $collection->find(); // Get Cursor

if ($products->count()) {

    foreach($products->sort(["price"=>1])->limit(5) as $product) {
        var_dump($product);
    }
}

Query collection

In general you can use a callback or simple array as criteria

$collection->find(function($document) {   // recommended to query data
    return $document["price"] > 10;
});

//or

$collection->find(["price"=>['$gt'=>10]]); // only very simple criteria is supported (can be slow)

//or just one

$collection->findOne(function($document) { ... });
$collection->findOne([...]);

Writing documents

$collection->insert($document);
$collection->save($document);
$collection->update($criteria, $data);

Delete documents

$collection->remove($criteria);

##API

Client

Client::listDBs()
Client::selectDB(databasename)
Client::selectCollection(databasename, collectionname)

Database

Database::vacuum()
Database::drop()
Database::createCollection(collectionname)
Database::dropCollection(collectionname)
Database::getCollectionNames()
Database::listCollections()
Database::selectCollection(collectionname)

Collection

Collection::drop()
Collection::renameCollection(newname)
Collection::insert(document)
Collection::save(document)
Collection::update(criteria, data)
Collection::remove(criteria)
Collection::count()
Collection::find(criteria)
Collection::findOne(criteria)

Cursor

Cursor::count()
Cursor::limit(number)
Cursor::skip(number)
Cursor::sort(array)
Cursor::each($callable)
Cursor::toArray()

Installation

To install and use MongoLite via the composer PHP package manager just take these steps:

If you don’t already have one, create the file composer.json in the root of your new project that is going to use MongoLite.

Add the following to the composer.json file..

{
    "require": {
        "agentejo/mongo-lite": "dev-master"
    }
}

Install composer (if it isn’t already installed):

curl -s https://getcomposer.org/installer | php
php composer.phar install

mongo-lite's People

Contributors

aheinze avatar bassauer-storms-media avatar charkes avatar faulancer avatar nbpalomino avatar stevendevooght avatar webcss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mongo-lite's Issues

why does the "_insert" method @ Collection.php return the sqlite-id instead of the generated id?

Hey Artur,

when one inserts a single entry to the DB, the insert method (which delegates to _insert) in the Collection.php returns the internal sqlite-ID of the new entry instead of the generated ID ($document['_id'] = isset($document['_id']) ? $document['_id'] : createMongoDbLikeId();).

Could the insert method please return the generated ID or is there a reason why the internal ID (which seems unused) is returned?

friendly regards

Document population

I started working on functionality to populate a document with another sub document. Currently oneToMany and ManyToMany scenario's are supported.

A document can be populated using the following method. The first argument is the property of the document you want to populate. The second argument is the name of the collection used to populate the document.

$collection->find()->populate("categories", "categories")->toArray();

For now only one level of population is supported. Everything is contained within the following commit: StevenDevooght@aefaee6

create_function deprecated in php 7.2

create_function in Database.php on line 82 deprecated in php 7.2

I try to use anomymous function, but i suck πŸ—‘

:: edit

            $this->document_criterias[$id] = function($document) use ($criteria) {
              $str = UtilArrayQuery::buildCondition($criteria);
              return eval("return $str;");
            };

quick fix :)

count documents

tell me how I can get the count of documents in the collection, not the full selected?
eg
the documentation is an example

$products = $collection->find();
$products->count()

so on large volumes of data will be noticeable brake

there is some variant like this?

$collection->count();

ie, in SQL, this query would look like this

select count(id) from table_name

numerical id

Prompt, as in certain collections can I specify numeric id (AUTO INCREMENT) ?

2 Question

Hello,

You are saying this is for small projects. Can I ask how small? Can you please give some numbers?

And the important one. How can I query for a json-object nested in an array and how?

Thank you very much for this incredible schemaless database.

password protection

tell me, how do I close the database with a password?
in documentation is not described, how to do it

Im thinking in working on a ServiceProvider for Silex microframework

Hello @aheinze

Thanks for this enjoyable project... πŸ‘

I was thinking if anybody is working on a ServiceProvider of MongoLite for Silex microframework... I ask for this because I will work in that project and maybe is usefull for somebody else...

Happy coding...

PS: I don't know how to mark this issue just as a "Enhancement" πŸ˜„

Delete some fields of document

First of all, sorry for my bad english (i'll try explain me) and thank you for this nice project, is very useful.

I'm trying delete some fields in a document, but when I execute "save" function with a new array including some fields erased and others added, the sql script only merge original json from DB with all new ones values added by me but no delete it.

How I could do this?

get id document

tell me how after use

$collection->insert($document);

I can in callback get an ID saved document?

using it without Composer install

hi
thanks for the good job
is it possible to using it with require way?
i like to keep my file structure clean and nice looking

how i can use it without vendor/autoload method?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.