Skip to content

[WIP] MongoDB Support#461

Closed
samvdb wants to merge 24 commits into
api-platform:masterfrom
samvdb:odm-support
Closed

[WIP] MongoDB Support#461
samvdb wants to merge 24 commits into
api-platform:masterfrom
samvdb:odm-support

Conversation

@samvdb

@samvdb samvdb commented Mar 16, 2016

Copy link
Copy Markdown
Contributor
Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? no
Fixed tickets #439, #361
License MIT

This is a work in progress. I will not be working on it but it might help others to get started.
Stuff to fix:

  • Add filters and enable them in the service xml
  • Add tests
  • Abstract ODM and ORM data providers since logic is duplicated
  • Abstract Paginator since it's duplicated
  • Move Query extension interfaces to data layer agnostic namespace
  • Filter/AbstractFilter should not contain ORM logic (see addJoinsForNestedProperty)
  • Add ext-mongo to travis-ci

@dunglas

dunglas commented Mar 16, 2016

Copy link
Copy Markdown
Member

About embedded documents, they are not resources (in sense of API Platform) but raw objects. IMO the best is do nothing: let the standard ObjectNormalizer of Symfony normalizing and denormalizing it (as we already do for ORM @Embeddable and \DateTime).

The only adaptation I can think about is documenting such embedded types in the Hydra ApiDocumentationGenerator and ContextBuilder but it can be done later in another PR.

@samvdb

samvdb commented Mar 16, 2016

Copy link
Copy Markdown
Contributor Author

@dunglas, i agree with you that embedded documents should not be processed as resources. However there were some problems in the old serializer (before refactor to symf abstract serializer).
My resources are beeing serialized atm without errors, embedded docs are still empty but that is probably a serialization context problem. Will test it out further. I hope other people are interested in mongo support and are willing to help out.

Thanks

@dunglas

dunglas commented Mar 16, 2016

Copy link
Copy Markdown
Member

Yes this problem has been figured out in the v2.

I'm personally very interested by Mongo support.

use ApiPlatform\Core\Bridge\Doctrine\MongoDB\Extension\QueryCollectionExtensionInterface;

/**
* Collection data provider for the Doctrine ORM.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doctrine MongoDB ODM.

@samvdb

samvdb commented Mar 16, 2016

Copy link
Copy Markdown
Contributor Author

@dunglas, what about the abstraction of the data providers or pagination extension?
I updated the rest of the comments

@samvdb

samvdb commented Mar 16, 2016

Copy link
Copy Markdown
Contributor Author

I can confirm that the serializer is working properly for embedded documents!

@dunglas

dunglas commented Mar 16, 2016

Copy link
Copy Markdown
Member

@dunglas, what about the abstraction of the data providers or pagination extension?

I've not got it.

@samvdb

samvdb commented Mar 16, 2016

Copy link
Copy Markdown
Contributor Author

@dunglas any idea how to fix the nelmio apidoc parser to support embedded documents?
Example: @Property(iri="https://schema.org/Offer", readableLink=false)
src/Metadata/Property/Factory/SerializerPropertyMetadataFactory.php:66 throws an exception because the document is not a resource and thus marking the property as a readable link.

When parsing the api it is being rendered as an IRI which is not correct.
see src/Bridge/NelmioApiDoc/Parser/ApiPlatformParser.php:194
Do you propose adding an extra property in the Annotation or create a workaround somewhere?

@dunglas

dunglas commented Mar 16, 2016

Copy link
Copy Markdown
Member

Maybe can we use the Symfony PropertyInfo component to list properties of this embedded object. Same apply for Hydra doc. But IMO it should be done in a separate PR. Let's focus on MongoDB support here.

@jonny827

Copy link
Copy Markdown

I am interested in support for DynamoDB and other non-MongoDB projects as well. Would it potentially be helpful to use an existing project to be able to push API-platform to several other platforms without "re-inventing the wheel"? You could benefit from their aligning several systems with a unified API. Use their API to communicate with API-platform. When they add support, we get all the benefits and you would only have to maintain the interface to their their API.

[https://github.com/doctrine/KeyValueStore]

/**
* @param ManagerRegistry $managerRegistry
* @param QueryCollectionExtensionInterface[] $collectionExtensions
* @param CollectionDataProviderInterface|null $decorated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My personal preference is to inject the decorated object as the first argument, so we can easily see that it's a decorator.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is best practice for arguments that are null by default to be listed last.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn't see that the decorated argument could be null. So... that means that it's not the "decorated" one, you should find another name.

@sroze

sroze commented Mar 17, 2016

Copy link
Copy Markdown
Contributor

Thank you @samvdb. Obviously we need to go through the review process before. :)

Can you add tests? Also, I can see that many of your classes are actually not used (because commented in the service.xml file), so could you add in your PR description a checkbox list of the tasks you've done and the tasks you have to do before we review it again?

@nettob

nettob commented Apr 14, 2016

Copy link
Copy Markdown

@eopaquette https://github.com/mongofill/mongofill is an pure PHP replacement of the MongoDB driver

@dunglas

dunglas commented May 9, 2016

Copy link
Copy Markdown
Member

Hello @samvdb, any update regarding this PR? It would be so cool to have it done for the v2.

@samvdb

samvdb commented May 9, 2016

Copy link
Copy Markdown
Contributor Author

Sorry kevin,

I'm using this branch as is, works fine but dont have the time to write
tests for it.

Gr

@coudenysj

Copy link
Copy Markdown
Contributor

@samvdb Any help needed on this?

@jonny827

Copy link
Copy Markdown

+1 for version 2. Need any help? I'm sure several of us could pitch in to help!

@samvdb

samvdb commented May 23, 2016 via email

Copy link
Copy Markdown
Contributor Author

@jonny827

jonny827 commented May 23, 2016

Copy link
Copy Markdown

@samvdb --- Can you please rebase your branch so that tests pass and resolve any conflicts? This will allow me to pull from your repo and try and write some tests(given my below experience level in this particular area) What from your perspective may be needed to allow other NOSQL databases hook into Api-Platform? Thank you for pushing to get this feature supported in the platform!

@coudenysj -- Can you please help with writing some tests? Secondly, thank you interest in helping bring MongoDB to the platform.

I was hoping DynamoDB would lead from the push towards ODM. I have never used a NOSQL DB. I do know there is great use cases for them that would blend with my project. So in short, I have never written a test; especially for a DB I have never used. Anyone have a good tutorial on MongoDB tests? I am not afraid to learn. Also, I was going to help with DOCS but realize the 2.x branch implementation pretty much would only need a few lines changed potentially for the docs to explain the support of ODM in addition to ORM which is probably best done by someone with clearer understanding of how those work.

To recap, if anyone has some resources for test writing for MongoDB or just in general please let me know. Secondly, if anyone find a place I fit in to progress this PR/the platform as a whole then please let me know!

@Simperfit

Copy link
Copy Markdown
Contributor

This PR is updated with master.

@samvdb Can you please give me a test project / or a path in order to test this ?

@ppounder

Copy link
Copy Markdown

Hi all,

Could anyone advise how close we are for this PR to be merged? I can see a few issues above, and possibly more so if it gets rebased. Where I work we are trying to set up using ApiPlatform and MongoDB so would be happy to try and test it in our environment.

We've already tried by running this, but it's not picking up our Document's so if anyone can point us in the right direction with a little help/documentation we can try and assist in getting this over the line.

Regards
Paul

@qneyrat

qneyrat commented Mar 22, 2017

Copy link
Copy Markdown

up, what's up?

@dunglas

dunglas commented Mar 22, 2017

Copy link
Copy Markdown
Member

Still waiting for a stable version of Mongo ODM for PHP 7 using the new extension (I've not checked but I'm not aware of a new release).

@qneyrat

qneyrat commented Mar 22, 2017

Copy link
Copy Markdown

I use mongo-php-adapter in prod. It's compulsory at the moment. I am afraid that doctrine upgrade in a long time. This repo is dev by one core developer and it's stable and it's recommended to use odm with php7.

@ad3n

ad3n commented Mar 27, 2017

Copy link
Copy Markdown
Contributor

I use MongoDB in PHP7 and as far as i use, i don't have any major issue about it

@ad3n

ad3n commented Apr 10, 2017

Copy link
Copy Markdown
Contributor

Just because change the root class (MongoDb Extension) that making stack? I don't know about it, but i think, if api platform can support mongodb, it is a good forward... We waiting for a year to support it... That is so long, right?

@dunglas

dunglas commented Apr 10, 2017

Copy link
Copy Markdown
Member

Ok to use the bridge if it is stable enough. But someone needs to finish this PR first (make Travis green and update the documentation).

@ad3n

ad3n commented Apr 11, 2017

Copy link
Copy Markdown
Contributor

@samvdb : can you help us to finish this PR? we need your help...

@qneyrat

qneyrat commented Apr 11, 2017

Copy link
Copy Markdown

If necessary I am available

@samvdb

samvdb commented Apr 11, 2017

Copy link
Copy Markdown
Contributor Author

I am no longer using this branch and have no time to spare atm. If anyone needs repo access i can grant it.

@soyuka

soyuka commented Apr 11, 2017

Copy link
Copy Markdown
Member

Anyone can fork your branch and create a new PR based on it :). @qneyrat feel free to do so, we will be glad to help reviewing!

rubenrua added a commit to rubenrua/Notes that referenced this pull request Jun 15, 2017
@ihr-it-projekt

ihr-it-projekt commented Jul 13, 2017

Copy link
Copy Markdown

i have fork this branch and merged it with the current master. If someone will help to make the lights green, i will be glad. https://github.com/ihr-it-projekt/core

PR: #1248

@samvdb Can you explain what i should do that api-plattform is right configured to use mongo db?

@Zayon Zayon mentioned this pull request Jul 28, 2017
@soyuka

soyuka commented Aug 28, 2017

Copy link
Copy Markdown
Member

Closing in favor of #1293 (continues this one).

@soyuka soyuka closed this Aug 28, 2017
leesiongchan pushed a commit to leesiongchan/api-platform-core that referenced this pull request Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.