Skip to content
Merged
32 changes: 32 additions & 0 deletions doc/7/controllers/collection/delete/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
code: true
type: page
title: delete
description: Deletes a collection
---

# delete

Deletes a collection.

<br/>

```js
delete(index, collection);
```

<br/>

| Arguments | Type | Description |
| ------------ | ----------------- | --------------- |
| `index` | <pre>string</pre> | Index name |
| `collection` | <pre>string</pre> | Collection name |


## Resolves

Resolves if the collection is successfully deleted.

## Usage

<<< ./snippets/delete-specifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
try {
await kuzzle.collection.delete('nyc-open-data', 'yellow-taxi');

console.log('Success');
} catch (error) {
console.error(error.message);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: collection#delete
description: Delete a collection
hooks:
before: curl -X POST kuzzle:7512/nyc-open-data/_create && curl -X PUT kuzzle:7512/nyc-open-data/yellow-taxi
after:
template: default
expected: Success
10 changes: 10 additions & 0 deletions src/controllers/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ class CollectionController extends BaseController {
}, options)
.then(response => response.result);
}

delete (index, collection) {
const request = {
index,
collection,
action: 'delete'
};
return this.query(request)
.then(() => undefined);
}
}

module.exports = CollectionController;
1 change: 0 additions & 1 deletion src/controllers/Index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class IndexController extends BaseController {
indexes
}
};

return this.query(request, options)
.then(response => response.result.deleted);
}
Expand Down
18 changes: 18 additions & 0 deletions test/controllers/collection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,22 @@ describe('Collection Controller', () => {
});
});
});

describe('delete', () => {
it('should call collection/delete query and return a promise which resolves an acknowledgement', () => {
kuzzle.query.resolves({result: {acknowledged: true}});
return kuzzle.collection.delete('index', 'collection')
.then(res => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith({
controller: 'collection',
action: 'delete',
index: 'index',
collection: 'collection',
});
should(res).be.undefined();
});
});
});
});