mongoose-shortid icon indicating copy to clipboard operation
mongoose-shortid copied to clipboard

Findbyid and populating

Open luluhoc opened this issue 4 years ago • 0 comments

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

  _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,
}); ```

luluhoc avatar Sep 20 '19 11:09 luluhoc