Code Monkey home page Code Monkey logo

mongodm's People

Contributors

amit777 avatar andreychuk avatar bperel avatar digitalkaoz avatar dongyaocn avatar jmartin82 avatar jrschumacher avatar juanfe190 avatar purekid avatar timothy-r avatar tusharvikky avatar wildsurfer 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mongodm's Issues

about the local config file path

in database.php

/**  Determine if use your local config file in place of this file   **/
$use_local_config = true;

/** The path of your config file , change to fit for your project.
 *         If your local config file does not exist,this config file will be used.
 * **/
$local_config_file = __DIR__."/../../../../application/config/mongodm.php";

if ($use_local_config && file_exists($local_config_file)) {
    $array = require $local_config_file;

    return $array;
}

can you change 'application' to 'app'?
because the laravel4 default application path is 'app'

[Insight] PHP code should follow PSR-1 basic coding standard

in src/Purekid/Mongodm/Model.php, line 658

Method names should be declared in camelCase. You should rename this class to comply with PSR-1.

     *
     * @param boolean $with_namespaces with namespaces
     *
     * @return string Name of class with namespaces stripped
     */
    public static function get_class_name($with_namespaces = true)
    {
        $class_name = get_called_class();
        if($with_namespaces) return $class_name;
        $class = explode('\\',  $class_name);

Posted from SensioLabsInsight

Model (with Reference to Json)

I have a function need to return a model in json (with all fields, several of them are references). The output, however, only gives "$id" and "$ref" fields instead of the referenced object.

Duplicated id in toArray() result

Here is a code of self-explanatory issue:

$data = array('a');
$athlete = new Athlete($data);
var_export($athlete->toArray());
$athlete->save();
var_export($athlete->toArray());

And the output:

array (
  0 => 'a',
  '_type' => 
  array (
    0 => 'Athlete',
  ),
)

array (
  0 => 'a',
  '_type' => 
  array (
    0 => 'Athlete',
  ),
  '_id' => 
  MongoId::__set_state(array(
     '$id' => '5272c0b08a14b53f748b45d5',
  )),
  '$id' => 
  MongoId::__set_state(array(
     '$id' => '5272c0b08a14b53f748b45d5',
  )),

Note that there are two ids after calling save() method. I noted it when tried to re-use data that I got from toArray() method to create new model:

$data = array('a');
$athlete = new Athlete($data);
$athlete->save();
$data1 = $athlete->toArray();

$athleteNew = new Athlete($data1);

Code above rises exception:

MongoCursorException: localhost:27017: document to insert can't have $ fields

Remove MongoId requirement

Hi!
as far as i can tell, the model _id has to be a MongoId. that isn't a requirement for mongodb and there are a few cases where specifying a different type of ID makes sense.

I would love to be able to use this ODM but that limitation prevents it ;(

MongoCursorException

Guys,

preciso tratar um problema, porem com try catch o mesmo continua a explodir. Podem me ajudar?

MongoCursorException [ 11000 ]:
localhost:27017: E11000 duplicate key error index: mobeli.users.$email_1 dup key: { : null }

Try:

public function action_test() {

    $signup = new \users\Model_Signup();
    $signup->first_name = "João Vagner";
    $signup->last_name = "Brito de Medeiros";
    $signup->emails = array('default' => '[email protected]');


    try {
        $signup->save();
    } catch (MongoCursorException $e) {
        echo "Exceção pega: ", $e->getMessage(), "\n";
    }


    die('oi');
}

Code style discussion

What is your preference on code style. I noticed that there are both tabs and spaces used. Two space and four space...

I propose moving to PSR-2

Issue creating new record using model constructor

Here is a simple test that will fail.

<?php

namespace Purekid\Mongodm\Test;

use Purekid\Mongodm\Test\TestCase\PhactoryTestCase;
use Purekid\Mongodm\Test\Model\Pupil;

class BugTest extends PhactoryTestCase {

    public function testInit()
    {
        $id = new \MongoId();
        $data = array('_id' => $id);
        $user = new Pupil($data);
        $user->save();

        $testUser = Pupil::id($id);

        $this->assertNotEmpty($testUser);

    }
}

This issue occurs when _Id is passed to constructor. As far as I see this is related to this line of code: https://github.com/purekid/mongodm/blob/master/src/Purekid/Mongodm/Model.php#L108

any examples with gridfs?

i am trying to use this with gridfs but am not sure if i need to create a modal for a file or not and can't seem to use set_file

Add "date" type

The timestamp type exists but I would like to create date fields, i.e. corresponding to MongoDate instances.

Bump version to 2.0, 1.5 or rollback a07259

@purekid I believe we need to bump version to 2.0 or at least 1.5 here at this commit a07259. This will be a breaking change to some developers who are checking the write state of their update queries.

Another option is to rollback and remove the ability to chain these methods since they have explicit purpose to the response.

Mongodm can not be use in Phalcon?

I have this question when create new model:
Argument 2 passed to Purekid\Mongodm\MongoDB::__construct() must be of the type array, null given, called in C:\xampp\htdocs\guppys\common\Library\Vendor\purekid\mongodm\src\Purekid\Mongodm\MongoDB.php on line 66 and defined

Packagist.org AutoUpdate Hook

Please add an auto update hook to packagist.org

It is highly recommended to set up the GitHub service hook for all your packages. This reduces the load on our side, and ensures your package is updated almost instantly. To do so you can go to your GitHub repository, click the "Admin" button, then "Service Hooks". Pick "Packagist" in the list, and add the API key you will find on your profile, plus your Packagist username if it is not the same as on GitHub. Check the "Active" box and submit the form.

mongo transaction

I recently met Mongo transaction trouble, I do not know how to deal with. I want to ask you is how to solve. Also, how to use mongo on your plugin findAndModifiy function?

Regex query is not working.

I am not sure what I am doing wrong but this below query is not working, can you help?

        if($this->input->has('filter')){
            $filter =  array( 'name' => array( '$regex' => $this->input->get('filter')) );
        }else{
            $filter = [];
        }
        $rawBrands = Brands::find($filter, ['name' => 1], [], 20, $skip);

I get no results, but if I executed the same query directly in mongodb I get lots of matched records, is $regex working in this lib?
The result that i get is always empty, but it should not be the case, either I should get all the brands or the brands that match the filter and yes I do have lots of documents in brand collection which match the search criteria.

2.0 proposal

For 2.0 of MongoDM I am proposing that we do some major refactoring to reorganize classes, optimize and implement more complex features.

Ideas:

  • refactor and optimize
  • break down Model class into multiple classes
  • implement plugin architecture (i.e. field conversion is a plugin rather than built into Model)
  • implement existing event system (Symfony?)

Drop collection

Hi,

Is there support yet to drop a collection, e.g. User::drop_collection()
or something similar?

Tests are passing but takes almost 1 minute

In our company we're considering an option to use mongodm in production.
We were trying to run tests and noticed that they are taking very long to pass on our server environement:

$ phpunit
PHPUnit 3.7.20 by Sebastian Bergmann.

Configuration read from /tmp/mongodm/phpunit.xml.dist

.........................

Time: 01:01, Memory: 3.75Mb

OK (25 tests, 56 assertions)
Press any key to continue...

Running phpunit with key --debug showed that it hangs up on 'TestHooks::testInit'.

At the same time it runs less than in a second on my laptop.

Any thoughts?

Regex example

How would I use regex to search through records? Would it be possible to regex through multiple keys?

Remove _id dependancy of MongoId

Need to enhance to remove the dependance of _id being a MongoId object or converting to it. Any helpers which do automatic conversation would be moved to a plugin rather than embedded into the core.

Adding to a Collection

Hi,

$a references $b

a) this works well
$b->save()
$a->b = Collection::make(array(new b));
$a->save()

b) this seems to work
$b->save()
$a->b->add(new b);
$a->save();
however when I read $a later on $a->b is empty
I am reading $a with A::id(..)

What am I doing wrong in b) ?

Add current tag

Added tags: 1.2.0 and 1.3.0

1.2.0 -> master
1.3.0 -> psr2-code-style

1:1 reference delete

Hi,

If I have A reference B
and then delete B like $b->delete()
A still maintains $db, $id, $ref values in the mongodb, is this correct? or am I deleting the reference wrongly?

Geolocation data handling

Are there any plans to add Geolocation data types at some stage ? It would be great to support GeoJSON types.

How are people currently handling simple location data (Points) in MongoDM currently ? Assuming a double array for latitude & longitute.

MongoDB extension?

Hi

Great work!

Any plans to release a version with pure MongoDB extension support?

Regards.

Switch between multiple databases

great package! is there an easy option to switch between different database using the same connection? preferably, have a $database complement $collection in the Model definition.

Edit and object

I have a object field which stores several different information depends on the instance.
Is there a way to modify the object's data and then save it?
Coz now it's not working as expected, like codes below.

$item->obj->value+=1;
$item->save();

this does not work

PHP 7 support?

The MongoDB extension installed via pecl for PHP 7 has changed a bit and it doesn't work with mongodm anymore. Are there any working branches for a port to the newer mongo lib?

Class '\Mongo' not found

That class and \MongoClient have been deprecated.
New one is MongoDB\Driver\Manager etc.

What is `_type` used for?

I am assuming it is used to maintain the association of an object if it doesn't have it's own collection like this.

class Person {
  public $collection = 'people';
}

class Student extends Person {}

However it adds a lot of unnecessary overhead to store _type unless someone is storing the different documents in the same collection. Let me know if this the only function because I want to build a dynamic switch (i.e. if there is no collection defined then set _type else omit)

Also I would suggest switching to a string rather than array. It is easier on the database with regards to storage and memory and would permit indexing. (i.e. Base\Person\Student)

Validate ad hoc data prior to save

Fields passed ad hoc should either be omitted or meet one of the datatype criteria.

For instance if an object is passed to mongodm it should either:

  • convert to string via __toString()
  • serialize
  • or omit

Find by Reference

Im trying to find a model based on reference, my code is below:

$user = \Models\User::id($id);
$threads = \Models\Thread::find(array('user' => $user));

And im geting the error "zero-length keys are not allowed, did you use $ with double quotes?"

Someone know what im doing wrong?
Thanks in advance and thanks for the great project.

slow to update

In my Mongodb is exist App and User collection, is 1:many relationship.
now, App has 1000 Users. my register code : '$app->users->add($user)'.
is very slow! when there are more and more registered users, the system is more and more slow.
so i viewed "Purekid\Mongodm\Model" source code, and i test ‘one’ method, i find when my call ‘$app->users->add($user)’, in "Purekid\Mongodm\Model::one" method will call "self::connection()->findOne(static::$collection, $criteria, self::mapFields($fields))" to load all
user document in memory. how to solve this...

English is not my native language, may I write some grammar mistakes, please understand

Inconsistent behavior when Mongo is not running

With MongoDB stopped mongodm throws an exception, which is expected.
But if we try to save something again, it crashes:

PHP Fatal error: Call to a member function selectCollection() on null in /home/willian/htdocs/test/vendor/purekid/mongodm/src/Purekid/Mongodm/MongoDB.php on line 708

<?php
require 'vendor/autoload.php';

\Purekid\Mongodm\MongoDB::setConfigBlock('default', array(
    'connection' => array(
        'hostnames' => 'localhost',
        'database'  => 'test'
    )
));

class Test extends \Purekid\Mongodm\Model {
    protected static $collection = "test";
}

$record = new Test();

try {
    $record->save();
}
catch (\Exception $e) {
    echo 'Catch exception #1 ', PHP_EOL;
}

try {
    $record->save();
}
catch (\Exception $e) {
    //
    echo 'Catch exception #2 ', PHP_EOL;
}

1:M relationship

I am trying to follow your example but not sure where I'm going wrong with this:

$user = new User();
$user->first_name = "tester";
$user->save();

$id = $user->_id;

$relationship = new Relationship();
$relationship->is_confirmed = true;
$relationship->save();

$user->relationships = Purekid\Mongodm\Collection::make(array($relationship));

$user->save();

Reading this exception:
MongoException: zero-length keys are not allowed, did you use $ with double quotes?

In User.php
'relationships' => array( 'model' => 'RelationShip', ' type' => 'references' )

Any hint?

Add Late Static Binding and fix some methods call (i.e. static instead of self)

There are a lot of calling like self::connection() in \Purekid\Mongodm\Model.
Why don't you use static::connection()?

Because of this issue I can't override some methods in my subclass.

For example:

class BaseModel extends \Purekid\Mongodm\Model
{
    // override \Purekid\Mongodm\Model::connection()
    protected static function connection()
    {
        die(__METHOD__);
    }
}

class Posts extends BaseModel
{
    // ...
}

Posts::one();

in this simple example method BaseModel::connection() will never be executed.

Moreover you use a lot of constructions like

$class = get_called_class();
$class::$config;
$class::getAttrs();

instead you should use

static::$config;
static::getAttrs();

Unique

Guys, What is the possibility or (stepping stones "Brazilian proverb"!) To implement a check for Unique. For example the input "email" should at least be unique.

A logic using postInsert or creating an attribute indicating that this Unique?

Lazy model update/remove

To improve speed to updating data I propose an optional model when updating data to lazily update by use of the findAndModify command.

Note: This option would make the assumption that you are content with the data you are saving. That is to say, when it gets executed it will replace data as specified.

Prototype

<?php

  // Goal:
  // 1. db.Person.findAndModify({_id: ObjectId('12345')}, {$set: {name: 'John Smith', age: 30}})
  // 2. Consistant API

  // defaults: sort = [], update = true, new = true
  $options = array(
    'sort' => array(),
    ['update' => true | 'remove' => true],
    'new' => true,
    'fields' => array(),
    'upsert' => false
  );

  Person::lazy($options); // or Person::findAndModify();
  $p = Person::id('12345');
  $p->name = 'John Smith';
  $p->age = 30;
  $p->save();

  //-- OR --

  // Create new methods (via trait) 
  $p = Person::pId('12345', $options);
  $p->name = 'John Smith';
  $p->age = 30;
  $p->save();

The choices we have from my perspective is either create some magic to set a flag for lazy/findAndModify/etc mode or clone existing functions.

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.