user663724
user663724

Reputation:

How to delete Collection using Mongo REST API?

I have registered with Mongolab and created my own Database and a collection .

My requeriemnet is that i need to delete the entire stock completely (that is body on load)

I was following this link

http://docs.mongolab.com/restapi/#delete-documents

But couldn't find anything related to deleting the entire collection ??

Please let me know if this is possible ??

The document shows this thing for deleting , but how can this help ??

$.ajax( { url: 'https://api.mongolab.com/api/1/databases/my-db/collections/my-coll?apiKey=myAPIKey',
          data: JSON.stringify( [ { "x" : 1 }, { "x" : 2 }, { "x" : 3 } ] ),
          type: "PUT",
          contentType: "application/json" } );

Upvotes: 1

Views: 1820

Answers (1)

John Powell
John Powell

Reputation: 12581

To delete the contents of the collection, but not drop the collection, you pass an empty array, [], in the Rest PUT request.

 $.ajax( { url: 'https://api.mongolab.com/api/1/databases/my-db/collections/my-coll?
    apiKey=myAPIKey',
      data: JSON.stringify([]),
      type: "PUT",
      contentType: "application/json" 
});

Upvotes: 4

Related Questions