node.js - Create hashid based on mongodb '_id` attribute -
i have mongo db schema follows:
var mytable = mongoose.model('items', { name: string, keyid: string });
i store keyid hashid of '_id' item being created. eg. say, add item db "hello world", , mongodb create '_id' item while inserting.
i make use of _id
use , generate hashid same item being inserted. this:
var hashids = require("hashids"), hashids = new hashids("this salt"); var id = hashids.encrypt("507f191e810c19729de860ea");
is there way, know id before hand. or let mongodb generate value id
field based on criteria specify.
just note on this. hashids module has encrypthex (or encodehex in v1.x), intended use mongodb ids.
Comments
Post a Comment