Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPORM-215 Implement Schema::getColumns and getIndexes #3045

Merged
merged 4 commits into from
Jul 16, 2024

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Jul 15, 2024

Fix PHPORM-215

This method is used by the command db:table:

Example of output:

php artisan db:table --database=mongodb users

  users .............................................................................................................  
  Columns ......................................................................................................... 8  
  Size ..................................................................................................... 60.00 KB  

  Column ....................................................................................................... Type  
  _id objectId ............................................................................................. objectId  
  created_at date, nullable .................................................................................... date  
  email string, nullable ..................................................................................... string  
  email_verified_at date, nullable ............................................................................. date  
  name string, nullable ...................................................................................... string  
  password string, nullable .................................................................................. string  
  remember_token string, nullable ............................................................................ string  
  updated_at date, nullable .................................................................................... date  

  Index .............................................................................................................  
  _id_ _id ......................................................................................... default, primary  
  email_1 email ..................................................................................... default, unique  


Checklist

  • Add tests and ensure they pass
  • Add an entry to the CHANGELOG.md file
  • Update documentation for new features

@GromNaN GromNaN requested a review from a team as a code owner July 15, 2024 14:18
@GromNaN GromNaN requested a review from alcaeus July 15, 2024 14:18
@@ -146,6 +151,70 @@ public function getTableListing()
return $collections;
}

public function getColumns($table)
Copy link
Member

Choose a reason for hiding this comment

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

This method could get slow for larger collections, so it may be worth adding a $sample pipeline stage down the road.

Depending on how much the feature is used, we can also consider expanding its functionality in a separate project to be more similar to Compass' schema analysis feature. For now, the current solution provides a good starting point.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we should try to replicate what is done by Compass. I added $sample and $limit stages.

Copy link
Member Author

@GromNaN GromNaN Jul 16, 2024

Choose a reason for hiding this comment

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

I tried on atlas sample dataset sample_airbnb.listingsAndReviews. With $sample, I get this error:

  PlanExecutor error during aggregation :: caused by :: Sort exceeded memory limit of 33554432 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in.

It works without it. There might be an optimization on the server for this use-case.

@GromNaN GromNaN merged commit c443240 into mongodb:4.7 Jul 16, 2024
26 checks passed
@GromNaN GromNaN deleted the PHPORM-215 branch July 16, 2024 13:26
@GromNaN GromNaN added this to the 4.7 milestone Jul 19, 2024
rustagir pushed a commit to rustagir/laravel-mongodb that referenced this pull request Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants