Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 99250

How can I append a object to a object using the Backend Services Javascript SDK?

$
0
0

Hi Eliandro,

To update an existing array field using the JavaScript SDK in your backend you use the native data queries operators ($push in your case - please see documentation on native operators). The code will look similar to the following:

var el = new Everlive('your-app-id');
.......


var data = el.data('type-name');
 
var attributes = {
    "$push": {
        "contacts": {
            "fisrtname": "Mary",
            "lastname": "Ann",
            "age": 27
        }
    }
};
 
var filter = {
    'Id': "item-id"
};
 
data.rawUpdate(attributes, filter, function(data) {
    console.log(JSON.stringify(data));
}, function(error) {
    console.log(JSON.stringify(error));
});

If you want to push multiple values to the array, you may use this:

var values = [{
    "fisrtname": "Mary",
    "lastname": "Ann",
    "age": 27
}, {
    "fisrtname": "John",
    "lastname": "Doe",
    "age": 32
}];
 
 
var attributes = {
    "$push": {
        "contacts": { "$each": values }
    }
};

Let me know if this has helped.

Regards,
Martin
Telerik by Progress
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 

Viewing all articles
Browse latest Browse all 99250

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>