Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

116
Vistas
Building an inbox system using Express/MongoDB

I have been developing an app for renting flats for a personal project of mine. I have been wondering about how to build/implement an inbox system to the current app which uses mongodb as database.

What does matter in such a feature? Would it be possible to define a schema called messages ?

var MessageSchema = new mongoose.Schema({
  message: String,
  sender : {
        id : {
            type : mongoose.Schema.Types.ObjectId,
            ref: "User"
          },
         username: String
    }
  recipient : {
        id : {
            type : mongoose.Schema.Types.ObjectId,
            ref: "User"
          },
         username: String
    }
)};

If I were to send a message to user y then it would be stored as recipient and the x value would be the sender. When I want to render a page called inbox could i do Messages.find({req.user._id) to sort all messages ? I am a bit lost in regards to the schema design.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

For schema, you probably want something like this:

const messageSchema = new mongoose.Schema({
  subject: String,
  body: String,
  seen: Boolean,
  sender: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "User"
  }
  recipient: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "User"
  }
})

const userSchema = new mongoose.Schema({
  username: String,
  email: Boolean,
  type: String
})

var Message = mongoose.model('Message', messageSchema);
var User = mongoose.model('User', userSchema);

For querying, you can find everything you need here

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda