Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

294
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda