Declarative Objectivity (DO) Language : Data Clauses : REMOVE Clause
REMOVE Clause
A REMOVE clause removes one or more elements from a collection.
Syntax 
removeClause : REMOVE (elementValue | elementValues | collectionElement | mapElementKeys) FROM targetCollection;
elementValue : expression ;
elementValues : '{' elementValue (',' elementValue)* '}' ;
mapElementKeys : KEYS '{' expression (',' expression)* '}';
targetCollection : reachableValue;
Used In 
UPDATE Statement
Quick Look 
Remove a date from a rental company’s list of high-volume dates:
UPDATE RentalCompany REMOVE 2017-01-31 FROM highVolumeDates RETURN highVolumeDates;
Remove two dates from a rental company’s list of high-volume dates:
UPDATE RentalCompany REMOVE {2017-01-31, 2017-07-05} FROM highVolumeDates RETURN highVolumeDates;
Remove the first date in a rental company’s list of high-volume dates and return the new first date (which was formerly the second date in the list):
UPDATE RentalCompany REMOVE highVolumeDates[0] FROM highVolumeDates RETURN highVolumeDates[0];
Remove the vehicle with the specified license from a rental company’s collection of vehicles (but not from the data store):
UPDATE RentalCompany REMOVE vehicles[license == 'XLT5663'] FROM vehicles;
Remove a customer from a rental company’s collection of customers, which is represented as a map with string keys:
UPDATE RentalCompany REMOVE KEYS{'fsmith123'} FROM customers;
Discussion 
A REMOVE clause occurs in an UPDATE Statement, and removes one or more elements from the target collection returned by the targetCollection expression. An error occurs if targetCollection does not return a single collection.
The target collection must be a variable-size collection. An error occurs if targetCollection returns a fixed-size collection.
The target collection may be the value of a direct or indirect attribute of the current context object.
You indicate an element to be removed by specifying an expression that returns the element’s value. The simplest way to do this is to provide an elementValue expression that returns a literal of the same type as the elements of the collection. For example:
UPDATE RentalCompany REMOVE 2017-01-31 FROM highVolumeDates RETURN highVolumeDates;
You can specify multiple elementValue expressions by separating them with commas and enclosing them in curly braces. For example:
UPDATE RentalCompany REMOVE {2017-01-31, 2017-07-05} FROM highVolumeDates RETURN highVolumeDates;
Note:If the target collection has duplicate values, all collection elements whose values match the literal are removed; see Removing From a Collection With Duplicate Values, below.
Removing From a List of Ordered Elements
When the target collection is a list (which orders its elements), you can remove the values at one or more index positions by specifying a collectionElement expression that designates an index or a range of indexes. Notice that targetCollection is the first operand of the subscript operator. For example:
UPDATE RentalCompany REMOVE highVolumeDates[0] FROM highVolumeDates;
Note:Indexes and ranges of indexes are supported only when the target collection is a list. They cannot be used with maps or sets; see Subscripts and Collection Types.
Warning:If the target collection has duplicate values, using an index or range subscript could remove more elements than you expect; see Removing From a Collection With Duplicate Values, below.
Warning:It is highly recommended that you verify any index positions you plan to use for removing element values. For example, you could query for all elements of the collection to verify the position of each unwanted element.
Removing From a Collection of References
When the elements of the target collection are references to persistent objects, you can indicate the element(s) to remove as follows:
You can specify an object-reference literal:
UPDATE RentalCompany REMOVE 3-3-1-20 FROM vehicles;
You can use a LET statement to query for the object of interest, and assign the result to a parameter. You then extract the reference from the parameter (see Obtaining a Reference to an Existing Object From a Parameter) and remove the reference from the collection:
LET rc = FROM RentalContract WHERE trackingNumber == 728 RETURN trackingNumber;
UPDATE Customer WHERE lastName == 'Mertz' REMOVE $rc[0].__identifier__ FROM rentals;
You can specify a collectionElement that provides a predicate expression for testing each referenced object in the collection. The REMOVE operation removes the elements for which the predicate evaluates to true. Notice that targetCollection is the first operand of the subscript operator:
UPDATE RentalCompany REMOVE vehicles[license == 'XLT5663'] FROM vehicles;
Note:If the collection has multiple elements for which the predicate expression evaluates to true, then multiple elements are removed from the collection.
Note:A REMOVE clause simply removes references from the target collection, without deleting any objects. (You use a DELETE Clause to delete an object from the federated database.)
Removing From a Collection of Bidirectional References
When the elements of a target collection are bidirectional references to persistent objects, the REMOVE operation automatically updates the element being removed in addition to updating the collection.
Example. The schema defines a bidirectional relationship between the Customer class and the RentalContract class through a pair of inverse reference attributes (namely, the Customer’s rentals attribute and the RentalContract’s customer attribute). This enables a customer to have multiple rental contracts, where each rental contract belongs to exactly one customer. Now consider what happens when a customer cancels a rental contract:
UPDATE Customer WHERE lastName == 'Mertz' REMOVE 3-3-1-8 FROM rentals RETURN rentals;
This statement not only removes the identified RentalContract from the Customer’s rentals collection, but also automatically clears the RentalContract’s customer attribute so that it no longer references the Customer.
Removing From a Collection of Embedded Objects
When the elements of the target collection are embedded objects, you can specify a collectionElement that provides a predicate expression for testing each object in the collection. The REMOVE operation removes the elements for which the predicate evaluates to true. The targetCollection expression is the first operand of the subscript operator.
Note:If the collection has multiple elements for which the predicate expression evaluates to true, then multiple elements are removed from the collection.
Removing From a Collection With Duplicate Values
When the target collection supports duplicate element values, the REMOVE clause removes all duplicates of each specified value. This applies to:
Lists, which can have multiple identical elements.
Maps, which can have multiple elements whose keys are unique and whose values are identical.
Note:A set cannot have duplicate elements, so at most one element in a set is removed for each value specified in a REMOVE clause.
It is important to understand that when a target collection contains duplicate values, an expression that evaluates to a single value could result in the removal of multiple elements. Thus, if you specify an elementValue expression that evaluates to a single literal value, the operation removes all collection elements whose values match the literal. For example, if the date 2017-01-31 has been added three times to the list held by highVolumeDates, the following statement removes all three elements:
UPDATE RentalCompany REMOVE 2017-01-31 FROM highVolumeDates RETURN highVolumeDates;
Similarly, if the Customer whose OID is 3-3-1-5 has been added three times (with three different keys) to the map held by customers, the following statement removes all three elements:
UPDATE RentalCompany REMOVE 3-3-1-5 FROM customers RETURN customers;
Note:Map elements with duplicate values are removed only when you specify a value. When you specify a key, only the element designated by that key is removed, even if that key’s value is also associated with other keys.
If the target collection is a list and you specify a collectionElement expression with an index subscript, you should understand that the expression evaluates to the value at the specified index position. If the collection contains duplicates of that value at other index positions, then the REMOVE operation removes the elements at those positions in addition to the element at the specified position.
Warning:If the target collection is a list that contains duplicates, be very careful when using a range subscript expression that evaluates to multiple values. Such an expression could remove many more elements than you expect.
Removing From a Map
When the target collection is a map, each element in it is a key:value pair, where the key and the value are of types specified by the map. A REMOVE operation always removes an entire map element (both key and value). You can use the CLEAR Clause to remove just the value associated with a key.
You typically indicate one or more map elements to be removed by:
Specifying one or more key(s) in a comma-separated list as follows:
UPDATE RentalCompany REMOVE KEYS{'fsmith123', 'bmartin004'} FROM customers;
Alternatively, you can indicate map elements to be removed by:
Specifying a single value as a literal:
UPDATE RentalCompany REMOVE 3-3-1-4 FROM customers;
Specifying multiple values as a comma-separated list of literals:
UPDATE RentalCompany REMOVE {3-3-1-4, 3-3-1-26} FROM customers;
Qualifying one or more values with a collectionElement that includes a predicate expression. Notice that targetCollection is the first operand of the subscript operator:
UPDATE RentalCompany REMOVE customers[rewardPoints < 10] FROM customers;
Note:Although a map always has unique keys, it may have elements with duplicate values. See Removing From a Collection With Duplicate Values.