content_image/754816.jpg content_image/754815.jpg
To insert an element at a different position in the array, use the arrayInsert()  method to specify which index to insert in the path expression. In this case, the index is 0, or the first element in the array. 

mysql-js> db.countryinfo.modify("Name = ’France’").arrayInsert("$.Airports[0]", "CDG") 

To delete an element from the array, you must pass to the arrayDelete()  method the index of the element to be deleted. 

mysql-js> db.countryinfo.modify("Name = ’France’").arrayDelete("$.Airports[1]") 

## Related Information 

•The MySQL Reference Manual provides instructions to help you search for and modify JSON values. 

## 20.3.3.5 Remove Documents 

•See CollectionModifyFunction for the full syntax definition. 

You can use the remove()  method to delete some or all documents from a collection in a schema. The X DevAPI provides additional methods for use with the remove()  method to filter and sort the documents to be removed. 

## Remove Documents Using Conditions 

The following example passes a search condition to the remove()  method. All documents matching the condition are removed from the countryinfo  collection. In this example, one document matches the condition. 

## Remove the First Document 

mysql-js> db.countryinfo.remove("Code = ’SEA’") 

To remove the first document in the countryinfo  collection, use the limit()  method with a value of 1. 

## Remove the Last Document in an Order 

mysql-js> db.countryinfo.remove("true").limit(1) 

The following example removes the last document in the countryinfo  collection by country name. 

## Remove All Documents in a Collection 

mysql-js> db.countryinfo.remove("true").sort(["Name desc"]).limit(1) 

You can remove all documents in a collection. To do so, use the remove("true")  method without specifying a search condition. 

<img src='content_image/754816.jpg'>

<img src='content_image/754815.jpg'>

## Caution 

Use care when you remove documents without specifying a search condition. This action deletes all documents from the collection. 

Alternatively, use the db.drop_collection(’countryinfo’)  operation to delete the countryinfo collection. 

## Related Information 

•See CollectionRemoveFunction for the full syntax definition. 

