Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
¿Hay alguna forma de simplificar el contenido (una de las columnas recuperadas de los datos de mongodb) usando monje?
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);})

Producción:

 [ { _id: 1, content: 'abcdefghijklmnopqrstu vwxyz ', }, { _id: 2, content: 'bcdefghijklmnopqrstuv wxy z', }, { _id: 3, content: 'cdefghijklmnopqrstuvw xy z', } ]

Intenté recuperar los datos de forma normal.

Pero, ¿hay alguna forma de recuperar solo las primeras palabras del contenido como se muestra a continuación?

 [ { _id: 1, content: 'abc d...', }, { _id: 2, content: 'bcd e...', }, { _id: 3, content: 'cde f....', } ]

Estoy tratando de usar collection.aggregate pero parece que no ayuda con el problema.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

parque infantil mongo

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!