Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions generator/config/expression/createObjectId.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# $schema: ../schema.json
name: $createObjectId
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/createObjectId/'
type:
- resolvesToObjectId
encode: object
description: |
Returns a random object ID
tests:
-
name: 'Example'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/createObjectId/#example'
pipeline:
-
$project:
objectId:
$createObjectId: {}
Copy link
Member Author

Choose a reason for hiding this comment

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

From the server source:

$createObjectId only accepts the empty object as argument

28 changes: 28 additions & 0 deletions src/Builder/Expression/CreateObjectIdOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Builder/Expression/FactoryTrait.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions tests/Builder/Expression/CreateObjectIdOperatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace MongoDB\Tests\Builder\Expression;

use MongoDB\Builder\Expression;
use MongoDB\Builder\Pipeline;
use MongoDB\Builder\Stage;
use MongoDB\Tests\Builder\PipelineTestCase;

/**
* Test $createObjectId expression
*/
class CreateObjectIdOperatorTest extends PipelineTestCase
{
public function testExample(): void
{
$pipeline = new Pipeline(
Stage::project(
objectId: Expression::createObjectId(),
),
);

$this->assertSamePipeline(Pipelines::CreateObjectIdExample, $pipeline);
}
}
17 changes: 17 additions & 0 deletions tests/Builder/Expression/Pipelines.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.