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

294
Views
MongoDB Java API: ¿cómo combinar la agregación de muestra con una consulta de búsqueda?

Necesito obtener una muestra aleatoria de documentos en una colección con un criterio de find .

 Bson sample = com.mongodb.client.model.Aggregates.sample(size); BasicDBObject query = new BasicDBObject().append("myKey", value);

¿Cómo puedo combinar esta agregación de sample con la consulta de find ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede usar la agregación con $match seguido de $sample .

 import static com.mongodb.client.model.Aggregates.*; import static com.mongodb.client.model.Filters.*; import static java.util.Arrays.asList; Bson match = match(eq("myKey", value)); Bson sample = sample(size); collection.aggregate(asList(match, sample));
over 4 years ago · Santiago Trujillo 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!