cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Remove Mongo from Phalcon

Open niden opened this issue 7 years ago • 18 comments

Since there is no support for the existing driver for PHP, we have to remove Mongo from this release.

There is a plan to re-introduce it in the future as a storage adapter and with that we can re-introduce the Mvc\Collection class or something similar

niden avatar Dec 24 '18 22:12 niden

What do You mean by removing Mongo? Remove direct "usage" of mongo in .zep and also remove ODM completely in 4.0 release?

ViltusVilks avatar Jan 03 '19 13:01 ViltusVilks

@ViltusVilks Remove the current driver (Mongo driver) that Phalcon uses to interact with Mongo because it has been deprecated. That will mean that the ODM will not work for a period of time until the new driver is introduced.

If we can do this in one go that would be great.

niden avatar Jan 03 '19 13:01 niden

Huh, deprecated? What is this? https://pecl.php.net/package/mongodb Or I do not understand what is deprecated (Phalcon support for ODM/Mongo compatibility, or Mongo decided to drop support for MongoDB native driver (NETLIB)?)

I am working on dokerized Phalcon-ODM-only project to make slim, fast and scalable image. Without ODM project is dead :(

ViltusVilks avatar Jan 03 '19 14:01 ViltusVilks

@ViltusVilks It is the driver itself. Phalcon has been using this driver:

http://php.net/manual/en/book.mongo.php

and we need to change it to this driver

http://php.net/manual/en/set.mongodb.php

niden avatar Jan 03 '19 14:01 niden

It is a matter of time and resources really. We have not "removed" anything with regards to the Mongo functionality. If you have the first driver installed then it will work I think. I really don't know the changes that 7.2 brought in that aspect of PHP.

Removing mongo functionality including the ODM in one release and reintroducing it properly tested and upgraded is the plan. It has not materialized yet since we have not finished the release - still in alpha

niden avatar Jan 03 '19 14:01 niden

Ah... this is old one driver! Just for information - I am using incubator github project, which overrides collection and uses new driver. I also utilize GridFS features.

And everything works fine php7.2.13 + 3.4.2 on Alpine 3.8 :) Have You checked that?

Shortcut - base collection class which is replacing Mvc\Collection. (i am using in Models namespace) https://github.com/phalcon/incubator/blob/master/Library/Phalcon/Mvc/MongoCollection.php

If that stuff can be "ported" to .zep ... on re-implemented /cleaned.

ViltusVilks avatar Jan 03 '19 15:01 ViltusVilks

I am using Phalcon MongoCollection and Client component to connect to mongo. It works as a charm. Phalcon version 3.4.1 Php 7.2 On Thu, 3 Jan 2019, 5:39 pm Juris Zeltiņš, [email protected] wrote:

Ah... this is old one driver! Just for information - I am using incubator https://github.com/phalcon/incubator github project, which overrides collection and uses new driver. I also utilize GridFS features.

And everything works fine php7.2.13 + 3.4.2 on Alpine 3.8 :) Have You checked that?

Shortcut - base collection class which is replacing Mvc\Collection. (i am using in Models namespace)

https://github.com/phalcon/incubator/blob/master/Library/Phalcon/Mvc/MongoCollection.php

If that stuff can be "ported" to .zep ... on re-implemented /cleaned.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/phalcon/cphalcon/issues/13697#issuecomment-451180460, or mute the thread https://github.com/notifications/unsubscribe-auth/AYmiiZ3nAeuAWY4XuSFsuTCWr14IIRgjks5u_iQcgaJpZM4Zgsd8 .

wajdijurry avatar Jan 03 '19 16:01 wajdijurry

@ViltusVilks Yes that is the plan. To upgrade the driver and clean things up. Right now we don't have a lot of time so this is why I wrote we need to remove it and bring it back fresh.

The "removal" will be temporary of course. We are not killing the component.

niden avatar Jan 03 '19 17:01 niden

@niden I thought we'd always had to use the incubator version and that was using the new driver (since php7.0?). I'm a complete mongo convert so this is kinda important to me. Very willing to take a look at this once I've got used to writing the tests etc.

npfedwards avatar Jan 04 '19 15:01 npfedwards

Yep, incubator is good and can be taken as an "example".

FYI: Just tryied to convert simple ODM models/code for Phalcon4 by modifing incubator code, it does not work, because of strict-type on interfaces on return types :(

Basically Phalcon4 should provide generic collection+manager with possibility to attach any backend adapter capable to handle Document store and query (incl. Solr, Elastic ...)

ViltusVilks avatar Jan 04 '19 15:01 ViltusVilks

@npfedwards More than welcome to give it a go i.e. have the incubator code completely tested and working with the new driver. Then we can relatively easily port it to zephir

@ViltusVilks I agree. I came up with this issue when I was trying to align the interfaces between find/findFirst of the model and find/findFirst of a document.

A brand new interface for a Document object is a must as you mentioned. We can then have adapters for the back end and handle any number of nosql or similar stores. That however will have to wait a bit until implemented.

I envision this:

  • Phalcon\Storage -> collection of low level adapters that will write data to a store. This could be file system, stream, Redis, Mongo or whatever. All use a simple interface to allow for more adapters (something in the lines of FlySystem from phptheleague)
  • Use those storage adapters everywhere: Cache, Metadata, Session etc.
  • Use wrapper around that adapter to offer Document objects for nosql or similar stores

niden avatar Jan 04 '19 22:01 niden

@niden Sure. I'll have a go making sure the current incubator code is tested (I've been using it for a while so I'm pretty sure it works ;)). And then given I want to expand my knowledge I'll have a go porting it to Zephir. I expect it to be a few week project for me but expect a pull request in a while.

npfedwards avatar Jan 05 '19 07:01 npfedwards

@npfedwards sounds like a plan. We have time so no worries. I need to figure out the Document class. How it will be and what it will have in it to help with all the crud and stuff. The existing one needs definitely some love.

niden avatar Jan 05 '19 15:01 niden

Some news. I have got working Phalcon v4.alpha2 (v 7.2.14 only, 7.3.1 has segmentation fault) with Incubator adapter and some small changes

Of cause you need do some code fixes like getSource() : string and etc typed returns for interface functions, but quering and save works fine :)

CollectionInterface, propper return type

/**
	 * Allows to query the first record that match the specified conditions
	 */
	public static function findFirst(array parameters = null) -> <CollectionInterface> | null;

MongoCollecto@Incubator, do the same

    // @codingStandardsIgnoreStart
    static protected $_disableEvents = false;
    // @codingStandardsIgnoreEnd

    public static function findFirst(array $parameters = null) : \Phalcon\Mvc\CollectionInterface
...

ViltusVilks avatar Feb 04 '19 16:02 ViltusVilks

@niden This is similar to what I was requesting as NFR [1] Its a great idea having Phalcon\Collection with CRUD support. It can use similar functions like in ODM [2] I specificly requested JSON adapter (flat-file-storage) because this is my own preference. But it can easily be extended to YAML and pure flat-file-storage similar to cache in Phalcon now but with much more control over it like sub-folders and search.

[1] https://github.com/phalcon/cphalcon/issues/13783 [2] https://docs.phalconphp.com/3.2/en/db-odm

ghost avatar Feb 09 '19 16:02 ghost

Does anyone have any updates on this?

SidRoberts avatar May 04 '19 02:05 SidRoberts

@SidRoberts From what I mentioned in a comment above, the storage adapters and the structure is there in the PSR-16 branch (my fork). Once that gets merged into 4.0.x we will have the structure to implement a mongo adapter using the latest driver. After that we can implement the Collection component that is aligned with the Resultset one.

There were a couple of members of the community that have been working on setting up the mongo collection with the latest mongo driver offering better compatibility with the latest and greatest mongo functionality.

Honestly I don't know about the timing on this i.e. whether we will have time to replace the mongo driver. For v4 we just might remove it and introduce it to v4.1. I think we can do this but I have to check SemVer if we can do it in a med version.

niden avatar May 04 '19 15:05 niden

Hello, I propose a (temporary) implementation while waiting for the total rewriting of the collections with MongoDb / PHP7. There is probably still work to be done, and unit tests must be done. The goal is to offer support for the new MongoDb driver for corporate projects

  • https://github.com/toroia/phalconator/tree/develop

tacxou avatar May 05 '19 11:05 tacxou