SHARE
TWEET

Untitled

a guest Jun 15th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let usuarios = new Schema({
  2.   nombre: {
  3.     type: String,
  4.     required: true
  5.   }
  6. }, { timestamps: true })
  7.  
  8. if (!usuarios.options.toObject) {
  9.   usuarios.options.toObject = {}
  10. }
  11.  
  12. usuarios.options.toObject.transform = (doc, usuario, options) => {
  13.   let idString = usuario._id.toString()
  14.   let longitud = idString.length
  15.   usuario.idShort = idString.substring((longitud - 5), longitud)
  16.   return usuario
  17. }
  18.      
  19. try {
  20.     res.json(await Usuarios.find(query))
  21.   } catch (error) {
  22.     next(error)
  23.   }
  24. })
  25.      
  26. [ { _id: 5cedb09bf795132cb47a467a,
  27.     updatedAt: 2019-05-28T22:05:15.851Z,
  28.     createdAt: 2019-05-28T22:05:15.851Z,
  29.     nombre: null,
  30.     __v: 0 },
  31.   { _id: 5cedb09bf795132cb47a467b,
  32.     updatedAt: 2019-05-28T22:05:15.880Z,
  33.     createdAt: 2019-05-28T22:05:15.880Z,
  34.     nombre: null,
  35.     __v: 0 } ]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top