-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RDoc-2566 Delete by query - 5.2 Node.js
- Loading branch information
1 parent
781d038
commit a9380c5
Showing
4 changed files
with
267 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
...en.Documentation.Pages/client-api/operations/common/delete-by-query.js.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# Delete by Query Operation | ||
--- | ||
|
||
{NOTE: } | ||
|
||
* Use `DeleteByQueryOperation` to delete a large number of documents that match the provided query in a single server call. | ||
|
||
* __Dynamic behavior__: | ||
The deletion of documents matching the specified query is run in batches of size 1024. | ||
During the deletion process, documents that are added/modified __after__ the delete operation has started | ||
may also be deleted if they match the query criteria. | ||
|
||
* __Background operation__: | ||
This operation is performed in the background on the server. | ||
If needed, you can __wait__ for the operation to complete. See: [Wait for completion](../../../client-api/operations/what-are-operations#wait-for-completion). | ||
|
||
* In this page: | ||
* [Delete by dynamic query](../../../client-api/operations/common/delete-by-query#delete-by-dynamic-query) | ||
* [Delete by index query](../../../client-api/operations/common/delete-by-query#delete-by-index-query) | ||
* [Syntax](../../../client-api/operations/common/delete-by-query#syntax) | ||
|
||
{NOTE/} | ||
|
||
{PANEL: Delete by dynamic query} | ||
|
||
{NOTE: } | ||
|
||
__Delete all documents in collection__: | ||
|
||
{CODE-TABS} | ||
{CODE-TAB:nodejs:DeleteOperation delete_by_query_0@ClientApi\Operations\Common\deleteByQuery.js /} | ||
{CODE-TAB-BLOCK:sql:RQL} | ||
from "Orders" | ||
{CODE-TAB-BLOCK/} | ||
{CODE-TABS/} | ||
|
||
{NOTE/} | ||
|
||
{NOTE: } | ||
|
||
__Delete with filtering__: | ||
|
||
{CODE-TABS} | ||
{CODE-TAB:nodejs:DeleteOperation delete_by_query_1@ClientApi\Operations\Common\deleteByQuery.js /} | ||
{CODE-TAB-BLOCK:sql:RQL} | ||
from "Orders" where Freight > 30 | ||
{CODE-TAB-BLOCK/} | ||
{CODE-TABS/} | ||
|
||
{NOTE/} | ||
|
||
{PANEL/} | ||
|
||
{PANEL: Delete by index query} | ||
|
||
* `DeleteByQueryOperation` can only be performed on a __Map-index__. | ||
An exception is thrown when executing the operation on a Map-Reduce index. | ||
|
||
* A few overloads are available, see the following examples: | ||
|
||
--- | ||
|
||
{NOTE: } | ||
|
||
__A sample Map-index__: | ||
|
||
{CODE:nodejs the_index@ClientApi\Operations\Common\deleteByQuery.js /} | ||
|
||
{NOTE/} | ||
|
||
{NOTE: } | ||
|
||
__Delete documents via an index query__: | ||
|
||
{CODE-TABS} | ||
{CODE-TAB:nodejs:DeleteOperation delete_by_query_2@ClientApi\Operations\Common\deleteByQuery.js /} | ||
{CODE-TAB:nodejs:DeleteOperation_overload delete_by_query_3@ClientApi\Operations\Common\deleteByQuery.js /} | ||
{CODE-TAB-BLOCK:sql:RQL} | ||
from index "Products/ByPrice" where Price > 10 | ||
{CODE-TAB-BLOCK/} | ||
{CODE-TABS/} | ||
|
||
{NOTE/} | ||
|
||
{NOTE: } | ||
|
||
__Delete with options__: | ||
|
||
{CODE-TABS} | ||
{CODE-TAB:nodejs:DeleteOperation delete_by_query_4@ClientApi\Operations\Common\deleteByQuery.js /} | ||
{CODE-TAB-BLOCK:sql:RQL} | ||
from index "Products/ByPrice" where Price > 10 | ||
{CODE-TAB-BLOCK/} | ||
{CODE-TABS/} | ||
|
||
* Specifying `options` is also supported by the other overload methods, see the Syntax section below. | ||
|
||
{NOTE/} | ||
|
||
{PANEL/} | ||
|
||
{PANEL: Syntax} | ||
|
||
{CODE:nodejs syntax_1@ClientApi\Operations\Common\deleteByQuery.js /} | ||
<br /> | ||
|
||
| Parameter | Type | Description | | ||
|-------------------|-----------------------------|------------------------------------------------------------| | ||
| __queryToDelete__ | string | The RQL query to perform | | ||
| __queryToDelete__ | `IndexQuery` | Holds all the information required to query an index | | ||
| __options__ | `object` | Object holding different setting options for the operation | | ||
|
||
{CODE:nodejs syntax_2@ClientApi\Operations\Common\DeleteByQuery.js /} | ||
|
||
{PANEL/} | ||
|
||
## Related Articles | ||
|
||
### Operations | ||
|
||
- [What are Operations](../../../client-api/operations/what-are-operations) | ||
|
||
### Client API | ||
|
||
- [How to Query](../../../client-api/session/querying/how-to-query) | ||
|
||
### Querying | ||
|
||
- [What is RQL](../../../client-api/session/querying/what-is-rql) | ||
- [Querying an index](../../../indexes/querying/query-index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
Documentation/5.2/Samples/nodejs/ClientApi/Operations/Common/deleteByQuery.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import { DocumentStore, AbstractIndexCreationTask } from "ravendb"; | ||
|
||
const store = new DocumentStore(); | ||
const session = store.openSession(); | ||
|
||
{ | ||
//region the_index | ||
// The index definition: | ||
// ===================== | ||
|
||
class Products_ByPrice extends AbstractJavaScriptIndexCreationTask { | ||
constructor () { | ||
super(); | ||
|
||
this.map("products", product => { | ||
return { | ||
Price: product.PricePerUnit | ||
}; | ||
}); | ||
} | ||
} | ||
//endregion | ||
|
||
async function deleteByQuery() { | ||
{ | ||
//region delete_by_query_0 | ||
// Define the delete by query operation, pass an RQL querying a collection | ||
const deleteByQueryOp = new DeleteByQueryOperation("from 'Orders'"); | ||
|
||
// Execute the operation by passing it to operations.send | ||
const operation = await store.operations.send(deleteByQueryOp); | ||
|
||
// All documents in collection 'Orders' will be deleted from the server. | ||
//endregion | ||
} | ||
|
||
{ | ||
//region delete_by_query_1 | ||
// Define the delete by query operation, pass an RQL querying a collection | ||
const deleteByQueryOp = new DeleteByQueryOperation("from 'Orders' where Freight > 30"); | ||
|
||
// Execute the operation by passing it to operations.send | ||
const operation = await store.operations.send(deleteByQueryOp); | ||
|
||
// * All documents matching the specified RQL will be deleted from the server. | ||
|
||
// * Since the dynamic query was made with a filtering condition, | ||
// an auto-index is generated (if no other matching auto-index already exists). | ||
//endregion | ||
} | ||
|
||
{ | ||
//region delete_by_query_2 | ||
// Define the delete by query operation, pass an RQL querying the index | ||
const deleteByQueryOp = | ||
new DeleteByQueryOperation("from index 'Products/ByPrice' where Price > 10"); | ||
|
||
// Execute the operation by passing it to operations.send | ||
const operation = await store.operations.send(deleteByQueryOp); | ||
|
||
// All documents with document-field PricePerUnit > 10 will be deleted from the server. | ||
//endregion | ||
} | ||
|
||
{ | ||
//region delete_by_query_3 | ||
// Define the index query, provide an RQL querying the index | ||
const indexQuery = new IndexQuery(); | ||
indexQuery.query = "from index 'Products/ByPrice' where Price > 10"; | ||
|
||
// Define the delete by query operation | ||
const deleteByQueryOp = new DeleteByQueryOperation(indexQuery); | ||
|
||
// Execute the operation by passing it to operations.send | ||
const operation = await store.operations.send(deleteByQueryOp); | ||
|
||
// All documents with document-field PricePerUnit > 10 will be deleted from the server. | ||
//endregion | ||
} | ||
|
||
{ | ||
//region delete_by_query_4 | ||
// QUERY: Define the index query, provide an RQL querying the index | ||
const indexQuery = new IndexQuery(); | ||
indexQuery.query = "from index 'Products/ByPrice' where Price > 10"; | ||
|
||
// OPTIONS: Define the operations options | ||
// (See all available options in the Syntax section below) | ||
const options = { | ||
// Allow the operation to operate even if index is stale | ||
allowStale: true, | ||
// Limit the number of base operations per second allowed. | ||
maxOpsPerSecond: 500 | ||
} | ||
|
||
// Define the delete by query operation | ||
const deleteByQueryOp = new DeleteByQueryOperation(indexQuery, options); | ||
|
||
// Execute the operation by passing it to operations.send | ||
const operation = await store.operations.send(deleteByQueryOp); | ||
|
||
// All documents with document-field PricePerUnit > 10 will be deleted from the server. | ||
//endregion | ||
} | ||
} | ||
} | ||
|
||
{ | ||
//region syntax_1 | ||
// Available overload: | ||
// =================== | ||
const deleteByQueryOp = new DeleteByQueryOperation(indexQuery); | ||
const deleteByQueryOp = new DeleteByQueryOperation(indexQuery, options); | ||
//endregion | ||
|
||
//region syntax_2 | ||
// options object | ||
{ | ||
// Indicates whether operations are allowed on stale indexes. | ||
allowStale, // boolean | ||
|
||
// If AllowStale is set to false and index is stale, | ||
// then this is the maximum timeout to wait for index to become non-stale. | ||
// If timeout is exceeded then exception is thrown. | ||
staleTimeout, // number | ||
|
||
// Limits the number of base operations per second allowed. | ||
maxOpsPerSecond, // number | ||
} | ||
//endregion | ||
} |