更新一条记录以添加对象错误(NodeJS)
Update One Record to add object Error(NodeJS)
我在玩我的 nodjs 和 mongoDB。我发现无法更新对象的错误。
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);
},
);
});
}
我试图通过使用 NestJS 插入一个地址(对象)。并收到此错误。
enter image description here
所以我想知道我做错了什么。我可以更新键:值,但我无法更新 key:object,
如果我输入一个空对象,它会起作用。
有没有人有answare?
问题是 coordinates: [123, 321]
不是有效坐标,这是因为 321
不是有效纬度值。纬度介于 -90 和 +90 之间,而经度可以介于 -180 和 +180 之间。
线索在错误消息中:"longitude/latitude out of bounds"
。
如果您确定您的坐标有效,则不应 运行 出现此错误。
对阅读有用的文档:
我在玩我的 nodjs 和 mongoDB。我发现无法更新对象的错误。
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);
},
);
});
}
我试图通过使用 NestJS 插入一个地址(对象)。并收到此错误。
enter image description here
所以我想知道我做错了什么。我可以更新键:值,但我无法更新 key:object, 如果我输入一个空对象,它会起作用。
有没有人有answare?
问题是 coordinates: [123, 321]
不是有效坐标,这是因为 321
不是有效纬度值。纬度介于 -90 和 +90 之间,而经度可以介于 -180 和 +180 之间。
线索在错误消息中:"longitude/latitude out of bounds"
。
如果您确定您的坐标有效,则不应 运行 出现此错误。
对阅读有用的文档: