简体   繁体   中英

Worklight WL.JSONStore Replace Doc failed

I have initialize a collection. In that i have a single doc which holds UserPreferences. I an trying to updated few fields of this doc. But fails with errorCallback.

var dataToUpdate = {
                                userPreferencesID:1,
                                firstname:'Test Name',
                                lastName: 'Test Name 2'};   
WL.JSONStore.get(tableName).replace(dataToUpdate).then(successCallback).fail(errorCallback);

If some forum i could see the syntax

WL.JSONStore.get(tableName).replace(query, option).then(successCallback).fail(errorCallback);

Which one is correct. I tried both, but failed to update the record.

IBM Worklight Version 6.1.0.2

Thank in advance.

The replace API takes a JSONStore document as the first parameter. For example:

{_id: 1, json: {userPreferencesID: 1, firstname: 'Test Name', lastName: 'Test Name 2'}}

Notice the _id and json keys. You're not passing a document as the first parameter.

Here's the API documentation for the replace API in Worklight v6.1.

You get JSONStore documents when you use, for example, the findAll API:

WL.JSONStore.get('collection').findAll()
.then(function (jsonstoreDocuments) {
  // [{_id: 1, json: {name: 'carlitos', age: 99}}]
});

The example above presumes the JSONStore collection is not empty, if it's empty you'll get an empty array back (ie [] ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM