Skip to content
Guido Barbaglia edited this page May 27, 2015 · 6 revisions

The service can be consumed through a PUT call to WDS and it is possible to update multiple rows/documents at once.

Parameter: "collection"

This parameter is used to specify the name of the collection, for MongoDB and OrientDB databases, or the name of the table, for SQL databases. New resources will be created in the specified collection/table.

Parameter: "payload"

The payload contains the query that selects the documents/rows to be updated and the object that represents the new document/row values.

{
   "query": {
      "state": "MA"
   },
   "update": {
      "state": "CA",
      "cities": [
         "San Diego",
         "San Francisco"
      ]
   }
}

MongoDB

In addition to the aforementioned parameters it is possible to specify two more options:

Name Description Default
upsert If no documents match the query, a new document is created in the collection. false
multi The update is applied to all the documents matching the query. false
{
   "query": {
      "state": "MA"
   },
   "update": {
      "state": "CA",
      "cities": [
         "San Diego",
         "San Francisco"
      ]
   },
   "upsert": true,
   "multi": true
}

Full Example

$.ajax({
                        
   type: 'PUT',
   url: 'rest/crud',
   data: {
      payload: {
         "query": {
            "state": "MA"
         },
         "update": {
            "state": "CA",
            "cities": [
               "San Diego",
               "San Francisco"
            ]
         },
         "upsert": true,
         "multi": true
      },
      datasource: "my_datasource",
      collection: "my_collection",
      outputType: "object"
   },
                        
   success: function (response) {
      /* Do something with the output... */
   },
                        
   error: function (a) {
      alert(a.responseText)
   }

});
Clone this wiki locally