Hello,
Code :
const Datastore = require('@google-cloud/datastore');
const datastore = Datastore({ projectId: 'lyl-api' });
function addConversationToUser(conversationKey, userKey) {
conversationKey = datastore.key(['Conversation', conversationKey]);
var query = datastore.createQuery('Conversation');
query.hasAncestor(conversationKey);
return datastore.runQuery(query, function (err, entity) {
entity = entity[0];
if (!entity.users) {
entity.users = [];
}
entity.users.push(userKey);
datastore.save(entity);
console.log(entity);
});
}
addConversationToUser(5681777339269120, 'hey');
addConversationToUser(5681777339269120, 'how');
addConversationToUser(5681777339269120, 'are');
addConversationToUser(5681777339269120, 'you');
Console ouput :
{ messages: [], name: 'Kazoo Kid', users: [ 'hey' ] }
{ messages: [], name: 'Kazoo Kid', users: [ 'are' ] }
{ messages: [], name: 'Kazoo Kid', users: [ 'how' ] }
{ messages: [], name: 'Kazoo Kid', users: [ 'you' ] }
Content of the datastore :
Identifiant
id=5681777339269120
Users
["are"]
Problem :
Only the last entity is saved.
If I add 'hey' and after that I add 'are', only 'are' is added. If I add after that 'how', only 'how' is added.
Is it a problem from Google ?
Hello,
Code :
Console ouput :
Content of the datastore :
Problem :
Only the last entity is saved.
If I add 'hey' and after that I add 'are', only 'are' is added. If I add after that 'how', only 'how' is added.
Is it a problem from Google ?