PHPackages                             lvinkim/mongo-odm - 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. [Database &amp; ORM](/categories/database)
4. /
5. lvinkim/mongo-odm

ActiveLibrary[Database &amp; ORM](/categories/database)

lvinkim/mongo-odm
=================

v0.4.1(7y ago)11961PHPPHP &gt;=7.1

Since Jul 24Pushed 7y ago2 watchersCompare

[ Source](https://github.com/lvinkim/mongo-odm)[ Packagist](https://packagist.org/packages/lvinkim/mongo-odm)[ RSS](/packages/lvinkim-mongo-odm/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (14)Used By (1)

mongo-odm
=========

[](#mongo-odm)

> 支持版本 mongodb 3.2.0 以上

### 安装

[](#安装)

```
$ composer require lvinkim/mongo-odm

```

### 方法概述

[](#方法概述)

- 通过 ID 获取单个 Entity 的方法：findOneById($id)
- 通过 filter 获取单个 Entity 的方法：findOne($filter)
- 通过 $filter 获取多个 Entity 的方法：findMany($filter, ...)
- 删除单个 Entity 的方法：deleteOne($entity)
- 通过 $filter 批量删除的方法：deleteMany($filter)
- 插入单个 Entity 的方法：insertOne($entity)
- 插入多个 Entity 的方法：insertMany($entities)
- 更新单个 Entity 的方法：updateOne($entity)
- 更新多个 Entity 的方法：updateMany($entities)
- 插入或更新单个 Entity 的方法：upsertOne($entity)
- 插入或更新多个 Entity 的方法：upsertMany($entities)

### 使用说明

[](#使用说明)

#### 步骤1. 定义 Entity

[](#步骤1-定义-entity)

```
use Lvinkim\MongoODM\Annotations as ODM;
use Lvinkim\MongoODM\Entity;
use MongoDB\BSON\ObjectId;

/**
 * Class User
 * @ODM\Entity()
 */
class User
{
    /**
     * @var ObjectId
     * @ODM\Id
     */
    private $id;
    /**
     * 名称
     * @var string
     * @ODM\Field(type="string")
     */
    private $name;

    /**
     * @return ObjectId
     */
    public function getId(): ?ObjectId
    {
        return $this->id;
    }

    /**
     * @param ObjectId $id
     */
    public function setId(ObjectId $id): void
    {
        $this->id = $id;
    }

    /**
     * @return string
     */
    public function getName(): string
    {
        return $this->name;
    }

    /**
     * @param string $name
     */
    public function setName(string $name): void
    {
        $this->name = $name;
    }
}
```

#### 步骤2. 定义 Repository 类

[](#步骤2-定义-repository-类)

```
use Lvinkim\MongoODM\Repository;

class UserRepository extends Repository
{

    /**
     * 返回数据库中的表名, 例如: db.user
     * @return string
     */
    protected function getNamespace(): string
    {
        return 'test.user';
    }

    /**
     * 返回数据表的对应实体类名
     * @return string
     */
    protected function getEntityClassName(): string
    {
        return User::class;
    }
}
```

#### 步骤3. 使用示例

[](#步骤3-使用示例)

```
use Lvinkim\MongoODM\DocumentManager;
use MongoDB\Driver\Manager;

$uri = 'mongodb://docker.for.mac.localhost';
$driver = new Manager($uri);

$documentManager = new DocumentManager($driver);
$userRepository = $documentManager->getRepository(UserRepository::class);

// 插入
$user = new User();
$user->setName("your name");
$userRepository->insertOne($user);

// 更多方法.... 参见 Functional/RepositoryTest.php 的各用例
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity55

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 ~17 days

Recently: every ~48 days

Total

13

Last Release

2642d ago

PHP version history (2 changes)v0.1.0PHP &gt;=7.0

v0.2.1PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/01d0ca591c3a6b31fb49935eb9ef6c2556ac5f1d44057d207fd06a5316b45457?d=identicon)[lvinkim](/maintainers/lvinkim)

---

Top Contributors

[![xiyanghui](https://avatars.githubusercontent.com/u/32087026?v=4)](https://github.com/xiyanghui "xiyanghui (15 commits)")

---

Tags

mogodbodmphp7

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lvinkim-mongo-odm/health.svg)

```
[![Health](https://phpackages.com/badges/lvinkim-mongo-odm/health.svg)](https://phpackages.com/packages/lvinkim-mongo-odm)
```

###  Alternatives

[doctrine/doctrine-module

Laminas Module that provides Doctrine basic functionality required for ORM and ODM modules

3957.9M116](/packages/doctrine-doctrine-module)[forkcms/forkcms

Fork is an open source CMS that will rock your world.

1.2k44.5k](/packages/forkcms-forkcms)[thecodingmachine/tdbm

The Database Machine is a PHP ORM that requires no configuration. The object model is deduced from the database model.

123174.9k6](/packages/thecodingmachine-tdbm)[nettrine/annotations

Doctrine Annotations for Nette Framework

193.0M7](/packages/nettrine-annotations)[onurb/doctrine-yuml-bundle

Symfony Bundle to visualize the mapping of your entities with Yuml

4198.6k](/packages/onurb-doctrine-yuml-bundle)[kdyby/annotations

Doctrine Annotations integration into Nette Framework

101.3M18](/packages/kdyby-annotations)

PHPackages © 2026

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