dylang / shortid

Short id generator. Url-friendly. Non-predictable. Cluster-compatible.
https://www.npmjs.org/package/shortid
Other
5.74k stars 258 forks source link

Can I use findbyid populate and equals? #149

Closed luluhoc closed 5 years ago

luluhoc commented 5 years ago

Hey,

I want to use shortid but I would love to know if it is possible to use equals() and how I can embed just the ids, for example, I have a user and I want to store in user schema all the liked posts (favShort in my schema) and then populate them this is my schema that is using object id for now

Also can I use findbyid with it?


  _id: {
    type: String,
    default: shortid.generate,
  },
  username: {
    type: String,
    lowercase: true,
    unique: true,
    required: true,
  },
  password: {
    type: String,
  },
  showNsfw: { type: Boolean, default: true },
  timezone: { type: String, default: 'CEST' },
  favShort: [{
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Shortcut',
  }],
  email: {
    type: String,
    lowercase: true,
    unique: true,
    required: true,
  },
  permissionLevel: { type: Number, default: 1 },
  role: {
    type: String,
    enum: ['member', 'moderator', 'premium', 'admin'],
    default: 'member',
  },
  country: String,
},
{
  timestamps: true,
}); ```
ai commented 5 years ago

I want to use shortid

Don't use shortid, it is deprecated. Use Nano ID.

Also can I use findbyid with it?

Nano ID (and shortid) generates simple string. I have no big experience with your DB, but you can use DB’s docs.