Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

CognitoSyncDataset.get(key, callback) returns "undefined" value. #51

Open
dap129 opened this issue Jul 5, 2017 · 1 comment
Open

CognitoSyncDataset.get(key, callback) returns "undefined" value. #51

dap129 opened this issue Jul 5, 2017 · 1 comment

Comments

@dap129
Copy link

dap129 commented Jul 5, 2017

After logging in and getting authenticated credentials for a user I want to create/read datasets for the user in cognito identity pool. I am able to create and read datasets from identity pool after which the records are getting stored in the browser's localStorage. But using 'get' and 'put' methods of "CognitoSyncDataset" in 'amazon-cognito-js' sdk, I am getting values for 'put' but getting "undefined" for get even though it is there in the localStorage. Here's my code:

var syncClient = new AWS.CognitoSyncManager();
syncClient.openOrCreateDataset("myDataset", function(err, dataset) {
              dataset.get("testk1", function(err, value) {
                if(err) console.log(err);
                else{
                  console.log("Record got:\n");
                  console.log(value);
                }
              });
              dataset.synchronize({
                onSuccess: function(dataset, newRecords) {
                  console.log('Successfully synchronized ' + newRecords.length + ' new records.');
                },
                onFailure: function(err) {
                  console.log('Synchronization failed.');
                  console.log(err);
                },
                onConflict: function(dataset, conflicts, callback) {
                  var resolved = [];
                  for (var i=0; i<conflicts.length; i++) {
                    // Take remote version.
                    // resolved.push(conflicts[i].resolveWithRemoteRecord());
                    // Or... take local version.
                    resolved.push(conflicts[i].resolveWithLocalRecord());

                    // Or... use custom logic.
                    // var newValue = conflicts[i].getRemoteRecord().getValue() + conflicts[i].getLocalRecord().getValue();
                    // resolved.push(conflicts[i].resovleWithValue(newValue);
                  }
                  dataset.resolve(resolved, function() {
                    return callback(true);
                  });
                  // Or... callback false to stop the synchronization process.
                  // return callback(false);
                }  
              });
            });
@tqhoughton
Copy link

tqhoughton commented Oct 24, 2017

I am also getting this error.

EDIT: After some more testing it appears that this is only an issue when attempting to retrieve datasets that were created in the AWS console. I ran some code that created a dataset, then tried getting it and it worked. Reloading the AWS console shows the newly created dataset as well. So I think this may be not be an issue unique to amazon-cognito-js but one that is linked to how the AWS console creates datasets.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants