devmachine/mongoimport
最新稳定版本:1.0.4
Composer 安装命令:
composer require devmachine/mongoimport
包简介
Import MongoDB export into Doctrine.
README 文档
README
PHP implementation of mongoimport.
About
Why would you need a custom mongoimport instead of default utility supplied with mongo? In certain setup (read Docker) mongo client is not available. With mongo extension enabled in PHP, you can import JSON created by mongoexport with this tiny library.
Provides integration with Symfony (read below), therefore could be used as fixtures loader.
Installation
Add the following to your composer.json:
{ "require": { "devmachine/mongoimport": "~1.0" } }
Usage
Import movies.json into hollywood database. Collection name is figured out automatically by using file's basename without extension.
$ ./bin/mongoimport movies.json --db hollywood
By default utility connects to mongod running on localhost:27017. In docker environment default host is MONGO_PORT_27017_TCP_ADDR and default port is MONGO_PORT_27017_TCP_PORT.
Overwriting default host, port and collection name:
$ ./bin/mongoimport movies.json -c shows --db hollywood --host <host> -p <port>
To drop existing collection prior to import, use --drop flag.
More info:
$ ./bin/mongoimport -h
Symfony integration
Register bundle in the kernel:
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle(), new Devmachine\MongoImport\Bundle\DevmachineMongoImportBundle(), ); }
When DoctrineMongoDBBundle is enabled it registers the importer in container for each ODM manager e.g.
devmachine_mongoimport.default(for default manager)devmachine_mongoimport.secondary(for secondary manager)devmachine_mongoimportalias for default importer.
Example:
// Import movies.json into "movies" collection in default database. $total = $this ->get('devmachine_mongoimport') ->importCollection('movies.json') ; // Drop existing collection prior to import. $total = $this ->get('devmachine_mongoimport') ->import('movies.json', ['drop' => true]) ; // With specified collection name. $total = $this ->get('devmachine_mongoimport') ->import('movies.json', 'films', ['drop' => true]) ; // With specified collection and db. $total = $this ->get('devmachine_mongoimport') ->import('movies.json', 'films', 'hollywood', ['drop' => true]) ;
Contributing
Find below various docker commands.
Init
$ docker-composer up -d # puts mongo container in bg
Load fixtures
$ docker-compose run --entrypoint php composer fixtures/load.php
Exporting data
From container:
$ mongoexport --db company --collection employees --jsonArray --pretty --out employees.json $ mongoexport --db company --collection offices --jsonArray --pretty --out offices.json
From host:
$ docker cp mongoimport_mongo_1:/employees.json ./tests/fixtures/ $ docker cp mongoimport_mongo_1:/offices.json ./tests/fixtures/
Running tests
$ docker-compose run --entrypoint php composer bin/phpunit
Running utility
$ docker-compose run --entrypoint php composer bin/mongoimport -V
devmachine/mongoimport 适用场景与选型建议
devmachine/mongoimport 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.81k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 10 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mongodb」 「import」 「doctrine」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 devmachine/mongoimport 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 devmachine/mongoimport 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 devmachine/mongoimport 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates Symfony2 documents, forms and CRUD
Parse use statements for a reflection object
Tool for copying data from a production database to a dev database. Also useful for making backups of production databases.
A fork of konnco/filament-import with support of Laravel 11 since the default importer of Filament 3 is nonsense for basic use case.
A package to allow laravel/passport use with mongodb/laravel-mongodb
Make pimcore migration simple
统计信息
- 总下载量: 8.81k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-29