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

207
Vistas
Is there any way to simplify the content (one of the column retrieved from the mongodb data) by using monk?
var monk = require('monk'); var db = monk('127.0.0.1:27017/db');
    
var collection = db.get('content'); newscol.find({}, {}).then((data) => {console.log(data);})

Output:

[
    {
    _id: 1,
    content: 'a b c d e f g h i j k l m n o p q r s t u v w x y z ',
    },
    {
    _id: 2,
    content: 'b c d e f g h i j k l m n o p q r s t u v w x y z',
    },
    {
    _id: 3,
    content: 'c d e f g h i j k l m n o p q r s t u v w x y z',
    }
]

Tried to retrieve the data in a normal way.

But is there any way to retrieve only the first few words of the content as below?

[
    {
    _id: 1,
    content: 'a b c d...',
    },
    {
    _id: 2,
    content: 'b c d e...',
    },
    {
    _id: 3,
    content: 'c d e f....',
    }
]

I am trying to use the collection.aggregate but seems it doesn't help with the problem.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

db.collection.aggregate([
  {
    $set: {
      content: {
        $reduce: {
          input: { $slice: [ { $split: [ "$content", " " ] }, 4 ] },
          initialValue: "",
          in: {
            $concat: [
              "$$value",
              { $cond: [ { $eq: [ "$$value", "" ] }, "", " " ] },
              "$$this"
            ]
          }
        }
      }
    }
  }
])

mongoplayground

about 4 years ago · Juan Pablo Isaza 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