Hello,
Thanks for sharing your logs with us. To save and update your existing document in saveORUpdateDocumentByKeyValue method, you need to send the correct key/value in the method code as shown below:
storageService.SaveOrUpdateDocumentByKeyValue(GameVars.dataDB, GameVars.collectionName, "_$owner.owner",OnAuthenticate.username, jsonDoc, new OnCoinsSaved());
}
public class OnCoinsSaved : App42CallBack
{
public void OnSuccess(object response)
{
Storage storage = (Storage)response;
App42Log.Console("dbName is " + storage.GetDbName());
App42Log.Console("collection Name is " + storage.GetCollectionName());
IList<Storage.JSONDocument> jsonDocList = storage.GetJsonDocList();
for (int i = 0; i < jsonDocList.Count; i++)
{
App42Log.Console("objectId is " + jsonDocList[i].GetDocId());
App42Log.Console("jsonDoc is " + jsonDocList[i].GetJsonDoc());
App42Log.Console("CreatedAt is : " + jsonDocList[i].GetCreatedAt());
App42Log.Console("UpdatedAt is : " + jsonDocList[i].GetUpdatedAt());
}
}
public void OnException(Exception e)
{
App42Log.Console("Exception : " + e);
}
}
Because in your case, your JSON document does not conatin a key who hold the value of username and same to fetch the document from Storage service, use the below line of code:
storageService.FindDocumentByKeyValue(GameVars.dataDB, GameVars.collectionName, "_$owner.owner",OnAuthenticate.username, new OnCoinsSaved());
}
public class OnCoinsSaved : App42CallBack
{
public void OnSuccess(object response)
{
Storage storage = (Storage)response;
App42Log.Console("dbName is " + storage.GetDbName());
App42Log.Console("collection Name is " + storage.GetCollectionName());
IList<Storage.JSONDocument> jsonDocList = storage.GetJsonDocList();
for (int i = 0; i < jsonDocList.Count; i++)
{
App42Log.Console("objectId is " + jsonDocList[i].GetDocId());
App42Log.Console("jsonDoc is " + jsonDocList[i].GetJsonDoc());
App42Log.Console("CreatedAt is : " + jsonDocList[i].GetCreatedAt());
App42Log.Console("UpdatedAt is : " + jsonDocList[i].GetUpdatedAt());
}
}
public void OnException(Exception e)
{
App42Log.Console("Exception : " + e);
}
}
Please check and let me know if it helps.
Thanks,
Himanshu Sharma
App42 Team