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

293
Vistas
Update One Record to add object Error(NodeJS)

I was playing with my nodjs and mongoDB. I found an error that I can not update a object.

const { MongoClient, ObjectID } = require('mongodb');
// or as an es module:
// import { MongoClient } from 'mongodb'

const url =
  'mongodb+srv://<user>:<password>@cluster0.uw6pe.mongodb.net/myFirstDatabase?retryWrites=true&w=majority';
console.log(url);
const client = new MongoClient(url);

// Database Name
const dbName = 'studio';

export async function insertData(_id: string) {
  // Use connect method to connect to the server
  await client.connect();
  console.log('Connected successfully to server');
  const db = client.db(dbName);
  const collection = db.collection('shops');

  return new Promise(function (resolve, reject) {
    collection.updateOne(
      { _id: ObjectID(_id) },
      {
        $set: {
          address: {
            type: 'Point',
            coordinates: [123, 321],
          },
        },
      },
      (err, res) => {
        if (err) reject(err);
        resolve(res);
      },
    );
  });
}

I was trying to insert an address(Object), by using NestJS. And got this error.

enter image description here

So I wonder what I did wrong. I could update key : value, but I can't update key:object, If I enter an empty object, it works.

Is there anyone who has an answare?

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

0

The issue is that coordinates: [123, 321] aren't valid coordinates, this is because 321 isn't a valid latitude value. Latitudes are between -90 and +90, whereas longitudes can be between -180 and +180.

The clue is in the error message: "longitude/latitude out of bounds".

If you make sure that your coordinates valid you shouldn't run into this error.

Useful docs for reading:

  • https://docs.mongodb.com/manual/geospatial-queries
  • https://en.wikipedia.org/wiki/Geographic_coordinate_syste
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