gpt4 book ai didi

javascript - 如何设置 GAE 数据存储的 key ?

转载 作者:太空宇宙 更新时间:2023-11-03 23:03:42 25 4
gpt4 key购买 nike

有人知道为什么当我向 /display-message 发出 GET 请求时,我总是收到此错误吗? { 错误:关键路径元素不得不完整:[created_timestamp: ]。我是否没有以正确的方式设置 key ?您可以在这里查看后台https://jarvis-hd-live-151521.appspot-preview.com/display-message?last_updated=0

const key = datastore.key('created_timestamp', 5689413791121408);

app.post('/message', function (request, response) {
let message = request.body.Body;
response.send("<Response><Message>Heyyo!</Message></Response>");

var d = new Date;
var time = d.getTime();

let entity = {
key: key,
data: {
message: message,
created: time
}
};


datastore.upsert(entity)
.then(() => {
console.log("Post UPDATED successfully");
});



});


app.get('/display-message', function(req,res){

let last_updated_time = req.query.last_updated;


function updateMessage(timestamp, message) {
var output = {
success: 1,
data: message,
timestamp: timestamp
};

return res.json(output);
}

function checkMessage() {
console.log("Starting to check message function");
var timeout;
clearTimeout(timeout);

datastore.get(key)
.then((entities) => {
let entity_data = entities[0];
console.log(entity_data);

let message_text = entity_data.message;
let new_timestamp_value = entity_data.created;

if(!last_updated_time || last_updated_time < new_timestamp_value) {
updateMessage(new_timestamp_value, message_text);
}
else {
console.log("No new messages at this time");

timeout = setTimeout(function(){
checkMessage();
}, 1000 * 10); //10 seconds
}

})
.catch(function(){
console.log("Promise Rejected");
console.log(err);
})
};

checkMessage();

});

最佳答案

我相信 datastore.key() 需要一个列表:

const key = datastore.key(['created_timestamp', 5689413791121408]);

https://googlecloudplatform.github.io/google-cloud-node/#/docs/datastore/0.6.0/datastore?method=key

关于javascript - 如何设置 GAE 数据存储的 key ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41307647/

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