Skip to content

how to use a custom text _id #1264

Closed
Closed
@gfanini

Description

@gfanini

how could I use a custom text _id like "0F000000" with the library, with php 7
since it is allowed by mongodb : https://docs.mongodb.com/manual/core/index-text/

$recordid='0F000000';
$uri = 'mongodb://'.$dbhost.$g_replicaSet;		
$client=new MongoDB\Client($uri);		
$collection = $client->test->test_collection;  	
$item = $collection->findOne(array('_id' => new MongoDB\BSON\ObjectId($recordid)));

this gives an exception, I tried with regex but it unexplainably does not fetch any records from some _id, how could I debug why
the cursor comes back empty with

$regex = new MongoDB\BSON\Regex ('0F000000', 'i');
$query = new MongoDB\Driver\Query( array('_id' => $regex) );

the same regex works in mongo shell, perhaps enabling debug trace in mongo php ? I am launching from php 7.4 and 8 cli, not from apache say

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions