Is there any way to create mongodb like _id strings without mongodb?

Use the official MongoDB BSON lib in the client
I have a browser client that generates ObjectIds. I wanted to make sure that I employ the same ObjectId algorithm in the client as the one used in the server. MongoDB has js-bson which can be used to accomplish that.

If you are using javascript with node.

npm install --save bson

Using require statement

var ObjectID = require('bson').ObjectID;

var id  = new ObjectID();
console.log(id.toString());

Using ES6 import statement

import { ObjectID } from 'bson';

const id  = new ObjectID();
console.log(id.toString());

The library also lets you import using good old script tags but I have not tried this.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)