[WIP] MongoDB Support #461
Conversation
About embedded documents, they are not resources (in sense of API Platform) but raw objects. IMO the best is do nothing: let the standard The only adaptation I can think about is documenting such embedded types in the Hydra |
@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). Thanks |
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. |
dunglas
Mar 16, 2016
Member
Doctrine MongoDB ODM.
Doctrine MongoDB ODM.
/** | ||
* Collection data provider for the Doctrine ORM. | ||
*/ | ||
class CollectionDataProvider implements CollectionDataProviderInterface |
dunglas
Mar 16, 2016
Member
Is this exactly the same class that the class for the ORM?
If it is the case, this class can be moved in the Doctrine
and used by both instead of being duplicated. If changes are small, an abstract
class can be introduced.
Is this exactly the same class that the class for the ORM?
If it is the case, this class can be moved in the Doctrine
and used by both instead of being duplicated. If changes are small, an abstract
class can be introduced.
samvdb
Mar 16, 2016
Author
Contributor
Yeah, the interfaces for query extensions should be pulled out of ORM also i think. The paginator could be abstracted since the only read difference if the getResult and applyToCollection.
If you want me to proceed with this give me the go ahead :)
Yeah, the interfaces for query extensions should be pulled out of ORM also i think. The paginator could be abstracted since the only read difference if the getResult and applyToCollection.
If you want me to proceed with this give me the go ahead :)
dunglas
Mar 16, 2016
Member
Yes 👍 for that.
Yes
@@ -61,6 +63,15 @@ public function getConfigTreeBuilder() | |||
->scalarNode('name_converter')->defaultNull()->info('Specify a name converter to use.')->end() | |||
->booleanNode('enable_fos_user')->defaultValue(false)->info('Enable the FOSUserBundle integration.')->end() | |||
->booleanNode('enable_nelmio_api_doc')->defaultTrue()->info('Enable the Nelmio Api doc integration.')->end() | |||
->scalarNode('db_driver') |
dunglas
Mar 16, 2016
Member
It would be nice to be able MongoDB and a relational DBMS at the same time.
It would be nice to be able MongoDB and a relational DBMS at the same time.
samvdb
Mar 16, 2016
Author
Contributor
mmm, maybe work towards a service definition like - managers: - orm: default_em, - mongodb: default_dm ?
mmm, maybe work towards a service definition like - managers: - orm: default_em, - mongodb: default_dm ?
dunglas
Mar 16, 2016
Member
Or just register the service if the MongoODMBundle is registered. If a user want to disable it, it can still use a compiler pass.
Or just register the service if the MongoODMBundle is registered. If a user want to disable it, it can still use a compiler pass.
dunglas
Mar 16, 2016
Member
Or better, flags like for FOSUser and NelmioApiDoc: enable_doctrine_orm, enable_doctrine_mongodb_odm.
Or better, flags like for FOSUser and NelmioApiDoc: enable_doctrine_orm, enable_doctrine_mongodb_odm.
->scalarNode('db_driver') | ||
->validate() | ||
->ifNotInArray($supportedDrivers) | ||
->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($supportedDrivers)) |
dunglas
Mar 16, 2016
Member
join()
?
join()
?
|
||
if (!$fetchData || $manager instanceof DocumentManager) { | ||
// @todo: Check potential problems with using the $id instead of $identifiers | ||
return $manager->getReference($resourceClass, $id); |
dunglas
Mar 16, 2016
Member
IIRC MongoDB doesn't support composed primary key? If so, it can be ignored and just use $identifierValues[0].
IIRC MongoDB doesn't support composed primary key? If so, it can be ignored and just use $identifierValues[0].
samvdb
Mar 16, 2016
Author
Contributor
There are severals options for compound keys, i would however not include support for this in this PR.
There are severals options for compound keys, i would however not include support for this in this PR.
@dunglas, what about the abstraction of the data providers or pagination extension? |
I can confirm that the serializer is working properly for embedded documents! |
I've not got it. |
@dunglas any idea how to fix the nelmio apidoc parser to support embedded documents? When parsing the api it is being rendered as an IRI which is not correct. |
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. |
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 |
sroze
Mar 17, 2016
Member
My personal preference is to inject the decorated object as the first argument, so we can easily see that it's a decorator.
My personal preference is to inject the decorated object as the first argument, so we can easily see that it's a decorator.
samvdb
Mar 17, 2016
Author
Contributor
I believe it is best practice for arguments that are null by default to be listed last.
I believe it is best practice for arguments that are null by default to be listed last.
sroze
Mar 17, 2016
Member
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.
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.
} | ||
|
||
$manager = $this->managerRegistry->getManagerForClass($resourceClass); | ||
if (null === $manager) { |
sroze
Mar 17, 2016
Member
Maybe you can merge these lines?
if (null === ($manager = $this->managerRegistry->getManagerForClass($resourceClass))) {
Maybe you can merge these lines?
if (null === ($manager = $this->managerRegistry->getManagerForClass($resourceClass))) {
$this->enabled = $enabled; | ||
$this->clientEnabled = $clientEnabled; | ||
$this->clientItemsPerPage = $clientItemsPerPage; | ||
$this->itemsPerPage = $itemsPerPage; |
sroze
Mar 17, 2016
Member
To me, we have too many parameters here. That would be nice to create a normalised PaginationConfiguration
object, that we could use both here and in the Doctrine implementation.
To me, we have too many parameters here. That would be nice to create a normalised PaginationConfiguration
object, that we could use both here and in the Doctrine implementation.
samvdb
Mar 17, 2016
Author
Contributor
Totally agree with you!
Totally agree with you!
return new Paginator($queryBuilder->getQuery()->execute()); | ||
} | ||
|
||
private function isPaginationEnabled(Request $request, ResourceMetadata $resourceMetadata, string $operationName = null) : bool |
sroze
Mar 17, 2016
Member
That looks like to be copy/pasted, or at least, that's not specific to MongoDb. Is there a way you can decouple that?
That looks like to be copy/pasted, or at least, that's not specific to MongoDb. Is there a way you can decouple that?
samvdb
Mar 17, 2016
Author
Contributor
It is copy pasted from the ORM version, don't have much time to work on it to cleanup everything. Like i said it's a PR kickstart mongo support :)
It is copy pasted from the ORM version, don't have much time to work on it to cleanup everything. Like i said it's a PR kickstart mongo support :)
sroze
Mar 17, 2016
Member
Yup, but you know... even if we tried to decouple from the ORM, it's always the first one that actually introduce the second real adapter that suffers 😛
Yup, but you know... even if we tried to decouple from the ORM, it's always the first one that actually introduce the second real adapter that suffers
theofidry
Mar 17, 2016
Member
😅
} | ||
|
||
$identifiers[$propertyName] = $identifierValues[$i]; | ||
++$i; |
sroze
Mar 17, 2016
Member
Instead of having this $i
variable, you can probably use the foreach ... as $i => $propertyName
.
Instead of having this $i
variable, you can probably use the foreach ... as $i => $propertyName
.
samvdb
Mar 17, 2016
Author
Contributor
This logic should also be abstracted since it's duplicated for ORM and ODM
This logic should also be abstracted since it's duplicated for ORM and ODM
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 |
@eopaquette https://github.com/mongofill/mongofill is an pure PHP replacement of the MongoDB driver |
Hello @samvdb, any update regarding this PR? It would be so cool to have it done for the v2. |
Sorry kevin, I'm using this branch as is, works fine but dont have the time to write Gr |
@samvdb Any help needed on this? |
+1 for version 2. Need any help? I'm sure several of us could pitch in to help! |
if someone could write tests for this code i'm pretty sure it could be
merged.
|
@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! |
- add symfony mongo test - add mongo on travis & appveyor
- add symfony mongo test - add mongo on travis & appveyor
This PR is updated with master. @samvdb Can you please give me a test project / or a path in order to test this ? |
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 |
up, what's up? |
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). |
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. |
I use MongoDB in PHP7 and as far as i use, i don't have any major issue about it |
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? |
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). |
@samvdb : can you help us to finish this PR? we need your help... |
If necessary I am available |
I am no longer using this branch and have no time to spare atm. If anyone needs repo access i can grant it. |
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! |
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? |
Closing in favor of #1293 (continues this one). |
[client] fixed the package name
This is a work in progress. I will not be working on it but it might help others to get started.
Stuff to fix: