SCUpdate
- SCUpdate
- .addOperator(oper: SCUpdateOperator)
- .set(dic: [String: SCValue])
- .push(name: String, _ value: SCValue)
- .pushEach(name: String, _ value: SCValue)
- .pull(name: String, _ value: SCPullable)
- .pullAll(name: String, _ value: SCValue)
- .addToSet(name: String, _ value: SCValue)
- .addToSetEach(name: String, _ value: SCValue)
- .pop(name: String, _ value: Int)
- .inc(name: String, _ value: SCValue)
- .currentDate(name: String, typeSpec: String)
- .mul(name: String, _ value: SCValue)
- .min(name: String, _ value: SCValue)
- .max(name: String, _ value: SCValue)
.addOperator(name, oper)
Method for transferring the SCUpdate operator to modify data
Parameters
Parameter | Type | Properties | Description | Value example |
---|---|---|---|---|
oper | SCUpdateOperator |
Mandatory | Sampling condition |
var update = SCUpdate()
let currentDate = SCUpdateOperator.currentDate("fieldName", typeSpec: "timestamp")
update.addOperator(currentDate)
.set(dic: [String: SCValue])
Method for transferring data to object
Parameter | Type | Properties | Description | Value example |
---|---|---|---|---|
dic | [String: SCValue] |
Object with data to be transferred to object | ["fieldString": SCString("NewValue")] |
Example
var update = SCUpdate()
update.set(["fieldName": SCString("A")])
.push(name: String, _ value: SCValue))
Method for adding an element to an array
Parameter | Type | Properties | Description | Value example |
---|---|---|---|---|
name | String |
Mandatory | Name of the field whose value should be updated | "tags" |
_ value | SCValue |
Mandatory | Value of the new array element | 42 |
Example
var update = SCUpdate()
update.push("fieldName", SCString("A"))
update.save()
.pushEach(name: String, _ value: SCValue))
Method for adding several elements to an array.
Parameter | Type | Properties | Description | Value example |
---|---|---|---|---|
name | String |
Mandatory | Name of the field whose value should be updated | "tags" |
_ value | SCValue |
Mandatory | Value of the new array element | 42, [43,43], 44 |
Example
var update = SCUpdate()
update.pushEach("fieldName", SCArray([SCString("A")]))
.pull(name: String, _ value: SCPullable)
Method for removing all array elements whose values are the same as the specified one.
Parameter | Type | Properties | Description | Value example |
---|---|---|---|---|
name | String |
Mandatory | Name of the field whose value should be updated | "tags" |
_ value | SCPullable |
Mandatory | Value to be removed | 42 |
Example
var update = SCUpdate()
update.pull("fieldName", SCString("A"))
.pullAll(name: String, _ value: SCValue)
Method for removing all array elements whose values are the same as one of the specified values.
Parameter | Type | Properties | Description | Value example |
---|---|---|---|---|
name | String |
Mandatory | Name of the field whose value should be updated | "tags" |
_ value | SCValue |
Mandatory | Array of values to be removed | [42, 44] |
Example
var update = SCUpdate()
update.pullAll("fieldName", SCArray([SCString("A")]))
.addToSet(name: String, _ value: SCValue)
Method for adding an element to an array only if there are no elements with the same name in the array.
Parameter | Type | Properties | Description | Value example |
---|---|---|---|---|
name | String |
Mandatory | Name of the field whose value should be updated | "tags" |
_ value | SCValue |
Mandatory | Value of the new array element | 42 |
Example
var update = SCUpdate()
update.addToSet("fieldName", SCString("A"))
.addToSetEach(name: String, _ value: SCValue)
Method for adding elements to an array only if there are no elements with the same name in the array.
Parameter | Type | Properties | Description | Value example |
---|---|---|---|---|
name | String |
Mandatory | Name of the field whose value should be updated | "tags" |
_ value | SCValue |
Mandatory | Array of new array element values | [42, 43] |
Example
var update = SCUpdate()
update.addToSetEach("fieldName", SCArray(SCString("A"))
.pop(name: String, _ value: Int)
Method for removing the first or the last array element
Parameter | Type | Properties | Description | Value example |
---|---|---|---|---|
name | String |
Mandatory | Name of the field whose value should be updated | "tags" |
_ value | Int |
Mandatory | Position of the element to be removed in the array: -1 for the first element and 1 for the last | -1 |
Example
var update = SCUpdate()
update.pop("fieldName", 1)
.inc(name: String, _ value: SCValue)
The method increments the numeric field value by a defined number
Parameter | Type | Properties | Description | Value example |
---|---|---|---|---|
name | String |
Mandatory | Name of the field whose value should be updated | "price" |
_ value | SCValue |
Mandatory | Increment step | 5 |
Example
var update = SCUpdate()
update.inc("fieldName", SCInt(1))
.currentDate(name: String, typeSpec: String)
Sets the current time as the field's value
Parameter | Type | Properties | Description | Value example |
---|---|---|---|---|
name | String |
Mandatory | Name of the field whose value should be updated | "price" |
typeSpec | SCValue |
Mandatory | Date type. Accepts the following values: true, "date" or "timestamp" | "timestamp" |
Example
var update = SCUpdate()
update.currentDate("fieldName", typeSpec: "date")
.mul(name: String, _ value: SCValue)
The method multiplies the numeric field value by a defined number
Parameter | Type | Properties | Description | Value example |
---|---|---|---|---|
name | String |
Mandatory | Name of the field whose value should be updated | "price" |
_ value | SCValue |
Mandatory | Multiplier | 2.5 |
Example
var update = SCUpdate()
update.mul("fieldName", SCInt(5))
.min(name: String, _ value: SCValue)
The method updates the numeric field value only if the new value is less than the current field value
Parameter | Type | Properties | Description | Value example |
---|---|---|---|---|
name | String |
Mandatory | Name of the field whose value should be updated | "price" |
_ value | SCValue |
Mandatory | New value | 42 |
Example
var update = SCUpdate()
update.min("fieldName", SCInt(5))
.max(name: String, _ value: SCValue)
The method updates the numeric field value only if the new value is greater than the current field value
Parameter | Type | Properties | Description | Value example |
---|---|---|---|---|
name | String |
Mandatory | Name of the field whose value should be updated | "price" |
_ value | SCValue |
Mandatory | New value | 42 |
Example
var update = SCUpdate()
update.max("fieldName", SCInt(5))