gpt4 book ai didi

node.js - 无法在 Node 中使用 GeoDataManager 查询 dynamoDb 数据

转载 作者:行者123 更新时间:2023-12-05 07:02:47 24 4
gpt4 key购买 nike

我正在尝试遵循此处给出的 Amazon DynamoDB 地理库的非常基本的教程 https://www.npmjs.com/package/dynamodb-geo .即使按照链接中提到的步骤进行操作,我的 myGeoTableManager.queryRadius() 调用也没有给我任何结果。以下是我遵循的步骤。

我用下面的脚本创建了 dynamoDB 表

require("dotenv").config();

var AWS= require('aws-sdk');

AWS.config.update({accessKeyId: process.env.accessKeyId, secretAccessKey: process.env.secretAccessKey, region: "us-east-1"});
const ddb = new AWS.DynamoDB();

const ddbGeo = require('dynamodb-geo');

const config = new ddbGeo.GeoDataManagerConfiguration(ddb, 'locationData');
config.hashKeyLength = 5;

const createTableInput = ddbGeo.GeoTableUtil.getCreateTableRequest(config);

// Tweak the schema as desired
createTableInput.ProvisionedThroughput.ReadCapacityUnits = 5;

console.log('Creating table with schema:');
console.dir(createTableInput, { depth: null });

// Create the table
ddb.createTable(createTableInput).promise()
// Wait for it to become ready
.then(function () { return ddb.waitFor('tableExists', { TableName: 'locationData' }).promise() })
.then(function () { console.log('Table created and ready!') });

然后我使用以下脚本在 dynamoDB 中插入和查询数据。

require("dotenv").config();

var AWS= require('aws-sdk');

AWS.config.update({accessKeyId: process.env.accessKeyId, secretAccessKey: process.env.secretAccessKey, region: "us-east-1"});
const ddb = new AWS.DynamoDB();

const ddbGeo = require('dynamodb-geo');

const config = new ddbGeo.GeoDataManagerConfiguration(ddb, 'locationData');
config.hashKeyLength = 5;

const myGeoTableManager = new ddbGeo.GeoDataManager(config);

myGeoTableManager.putPoint({
RangeKeyValue: { S: '1234' },
GeoPoint: {
latitude: 28.749472,
longitude: 77.056534
},
PutItemInput: {
Item: {
country: { S: 'country1' },
capital: { S: 'capital1' }
},
}
}).promise()
.then(function() { console.log('Insert Done!') });

myGeoTableManager.putPoint({
RangeKeyValue: { S: '5678' },
GeoPoint: {
latitude: 28.749999,
longitude: 77.056999
},
PutItemInput: {
Item: {
country: { S: 'country2' },
capital: { S: 'capital2' }
},
}
}).promise()
.then(function() { console.log('Insert Done!') });

myGeoTableManager.queryRadius({
RadiusInMeter: 100000,
CenterPoint: {
latitude: 28.749888,
longitude: 77.056888
}
}).then((locations) => {
console.log(locations);
});

即使纬度和经度完全相同,myGeoTableManager.queryRadius() 也会给我空响应。

最佳答案

有更新版本 https://github.com/renet/dynamodb-geo-v3 可用,支持 AWS 3.* 版本。

关于node.js - 无法在 Node 中使用 GeoDataManager 查询 dynamoDb 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63429443/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com