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

292
Views
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 answers
Answer question

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 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!