@@ -122,6 +122,29 @@ KuzzleDataCollection.prototype.count = function (filters, options, cb) {
122122 return this ;
123123} ;
124124
125+ /**
126+ * Create a new empty data collection, with no associated mapping.
127+ * Kuzzle automatically creates data collections when storing documents, but there are cases where we
128+ * want to create and prepare data collections before storing documents in it.
129+ *
130+ * @param {object } [options] - Optional parameters
131+ * @param {responseCallback } [cb] - returns Kuzzle's response
132+ * @returns {* } this
133+ */
134+ KuzzleDataCollection . prototype . create = function ( options , cb ) {
135+ var data = { } ;
136+
137+ if ( ! cb && typeof options === 'function' ) {
138+ cb = options ;
139+ options = null ;
140+ }
141+
142+ data = this . kuzzle . addHeaders ( data , this . headers ) ;
143+ this . kuzzle . query ( this . collection , 'write' , 'createCollection' , data , options , cb ) ;
144+
145+ return this ;
146+ } ;
147+
125148/**
126149 * Create a new document in Kuzzle.
127150 *
@@ -176,6 +199,27 @@ KuzzleDataCollection.prototype.createDocument = function (document, options, cb)
176199 return this ;
177200} ;
178201
202+ /**
203+ * Delete this data collection and all documents in it.
204+ *
205+ * @param {object } [options] - Optional parameters
206+ * @param {responseCallback } [cb] - returns Kuzzle's response
207+ * @returns {* } this
208+ */
209+ KuzzleDataCollection . prototype . delete = function ( options , cb ) {
210+ var data = { } ;
211+
212+ if ( ! cb && typeof options === 'function' ) {
213+ cb = options ;
214+ options = null ;
215+ }
216+
217+ data = this . kuzzle . addHeaders ( data , this . headers ) ;
218+ this . kuzzle . query ( this . collection , 'admin' , 'deleteCollection' , data , options , cb ) ;
219+
220+ return this ;
221+ } ;
222+
179223/**
180224 * Delete persistent documents.
181225 *
@@ -389,14 +433,36 @@ KuzzleDataCollection.prototype.replaceDocument = function (documentId, content,
389433KuzzleDataCollection . prototype . subscribe = function ( filters , cb , options ) {
390434 var room ;
391435
392- this . kuzzle . isValid ( ) ;
393436 this . kuzzle . callbackRequired ( 'KuzzleDataCollection.subscribe' , cb ) ;
394437
395438 room = new KuzzleRoom ( this , options ) ;
396439
397440 return room . renew ( filters , cb ) ;
398441} ;
399442
443+ /**
444+ * Truncate the data collection, removing all stored documents but keeping all associated mappings.
445+ * This method is a lot faster than removing all documents using a query.
446+ *
447+ * @param {object } [options] - Optional parameters
448+ * @param {responseCallback } [cb] - returns Kuzzle's response
449+ * @returns {* } this
450+ */
451+ KuzzleDataCollection . prototype . truncate = function ( options , cb ) {
452+ var data = { } ;
453+
454+ if ( ! cb && typeof options === 'function' ) {
455+ cb = options ;
456+ options = null ;
457+ }
458+
459+ data = this . kuzzle . addHeaders ( data , this . headers ) ;
460+ this . kuzzle . query ( this . collection , 'admin' , 'truncateCollection' , data , options , cb ) ;
461+
462+ return this ;
463+ } ;
464+
465+
400466/**
401467 * Update parts of a document
402468 *
0 commit comments