PHPackages                             kanin/my-tools - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kanin/my-tools

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kanin/my-tools
==============

各种常用工具类封装

v1.0.8(3y ago)111MITPHPPHP &gt;=7.0

Since Aug 12Pushed 3y ago1 watchersCompare

[ Source](https://github.com/tangccy/my-tools)[ Packagist](https://packagist.org/packages/kanin/my-tools)[ RSS](/packages/kanin-my-tools/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (7)Used By (0)

my-tools
========

[](#my-tools)

常用工具类封装，目前已经封装mongodb

安装
--

[](#安装)

```
composer require kanin/my-tools
```

KMmongo使用
---------

[](#kmmongo使用)

> 具体每个参数要到方法里面去看

### 实例化

[](#实例化)

```
$ip = '127.0.0.1';
$port = '27017';
$username = "kanin";
$password = "123456";

//实例化
$manager = new \Kanin\MyTools\KMongo($ip, $port, $username, $password);
```

### 插入

[](#插入)

```
//单条插入
$document =['_id'=>1, 'name'=>'小明'];
$res = $manager->setCollection('blog.users')->insert($document);

//多条插入
$document = [
	['_id'=>2, 'name'=>'小明2'],
	['_id'=>3, 'name'=>'小明3'],
	['_id'=>4, 'name'=>'小明4'],
];
$res = $manager->collection('blog.users')->insertAll($document);
```

### 更新

[](#更新)

```
$set = ['name'=>'xiaomin'];
$filter = ['_id'=>1];
$res = $manager->collection('blog.users')->filter($filter)->update(['$set'=>$set], ['upsert' => false]);
```

### 查询

[](#查询)

```
//count统计-获取表文档总条数
$count = $manager->collection('blog.users')->count();

//过滤条件
$filter = ['_id' => ['$gt' => 1]];

//单条查询
$data = $manager->collection('blog.users')->limit(1, 1)->filter($filter)->getOne();

//批量查询
$data = $manager->collection('blog.users')->limit(1, 1)->filter($filter)->getAll();

//原始查询 (数据没转换) 上面的两个查询都是基于这个
$data = $manager->collection('blog.users')->limit(1, 1)->filter($filter)->get();

/**
 * where 仿orm操作  类似于mysql的查询组合  _id>2 and (_id=3 or _id=4)
 * 目前支持的操作符
 * =        等于
 * <        小于
 *         大于
 * >=       大于等于
 * 或!=   不等于
 * in   in查询
 * nin  not in 查询
 *
 * 展示指定字段
 * field(['email'=>1, 'name'=>1,'_id'=>0])
 * 1是展示 0是排除
 * 要注意一下，用email=1, name=0是不行的，mongo官方会提示逻辑错误，除了_id可以自由设置0或1，其他字段要么全是1，要么全是0
 *
 * 排序
 * sort($field, $desc)
 * $desc 1是升序，-1是降序  只能填1或者-1
*/
$collection = 'blog.users';
$find = $manager->collection($collection)
	->where('_id', '>', 2)
	->whereOr('_id', '=', 3)
	->whereOr('_id', '=', 4)
	->field(['name'=>1, 'email'=>1, '_id'=>0])
	->sort('_id', -1)
	->getAll();

```

### 删除

[](#删除)

```
//过滤条件
$filter = ['_id' => ['$gt' => 1]];
$manager->collection('blog.users')->filter($filter)->delete();
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

6

Last Release

1362d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7269a5ccf967c0f029f2c93c67081c47216a53bd4564f0cf5d6a2ca5f6778b48?d=identicon)[Kanin](/maintainers/Kanin)

---

Top Contributors

[![tangccy](https://avatars.githubusercontent.com/u/12172453?v=4)](https://github.com/tangccy "tangccy (18 commits)")

### Embed Badge

![Health badge](/badges/kanin-my-tools/health.svg)

```
[![Health](https://phpackages.com/badges/kanin-my-tools/health.svg)](https://phpackages.com/packages/kanin-my-tools)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
