Skip to content

Custom _id with a pre-generated _id #225

@nanchet

Description

@nanchet

Hi!

I have an ObjectId generator in Javascript, which generates "_id" like "5394d7db560c9869a1000002", But when I pass this "_id" to "Moloquent" to do an insert it stores as a string instead of an ObjectId like "ObjectId('5394d7db560c9869a1000002')".

The only way I have found to solve this is to make a new MongoId with the pre-generated "_id".

$this->_id  = new MongoId($obj['_id']);
$this->name = $obj['name'];
$this->save();

There is another more elegant way to do this? Thanks!

PD: (Sorry for my english)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions