簡體   English   中英

無法在節點中使用 GeoDataManager 查詢 dynamoDb 數據

[英]Not able to query dynamoDb data using GeoDataManager in Node

我正在嘗試遵循此處給出的 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/r.net/dynamodb-geo-v3可用,它支持 AWS 3.* 版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM