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

144
Views
Error de consulta de MongoDB

He guardado la siguiente consulta como med.js

 var cust = db.Collection.find({"email":null}); var count = 0; print("total entries: ",cust.length()," ",cust.hasNext()); while(cust.hasNext()){ nextCust = cust.next(); db.Collection.update({_id:nextCust._id},{$set : {"email":""}}); count++; } print("total updated: ",count);

Cuando estoy ejecutando esta consulta como
mongo dbName --puerto 13017 ~/Documentos/med.js

la salida es el total de entradas: 491502 falso
total actualizado: 0

¿Cómo es que las entradas totales se muestran como 491502 pero hasNext() es falso? no va en el ciclo while

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

La función cursor.length() agota el cursor convirtiéndolo en una matriz. Compruebe el código de función.

 >cur.length function (){ return this.toArray().length; }

Por lo tanto, te estás volviendo false .

Para obtener el conteo sin agotar el cursor, use cursor.count()

over 4 years ago · Santiago Trujillo Report

0

Hay tres métodos diferentes que puede utilizar en este contexto.

  • cursor.count() Modifica el cursor para devolver el número de documentos en el conjunto de resultados en lugar de los documentos en sí.

  • cursor.itcount() Calcula el número total de documentos en el lado del cliente del cursor obteniendo e iterando el conjunto de resultados.

  • cursor.size() Devuelve un recuento de los documentos en el cursor después de aplicar los métodos skip() y limit().

cursor.length no es un enfoque recomendado.

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!