%% Remove Documents Using MongoDB Query
% Connect to MongoDB® using the MongoDB C++ interface and remove documents from a collection. Specify a MongoDB query to determine which documents to remove. In this example, the collection represents employee data.
%
% Create a MongoDB connection to the database mongotest using the MongoDB C++ interface. Here, the database server dbtb01 hosts this database using port number 27017.

server = "dbtb01";
port = 27017;
dbname = "mongotest";
conn = mongoc(server,port,dbname)

% conn is the connection object that contains the MongoDB connection. The object properties contain information about the connection and the database.
% The database name is mongotest.
% The user name is blank.
% The database server is dbtb01.
% The port number is 27017.
% This database contains 14 document collections.
%
% Verify the MongoDB connection.

isopen(conn)

% The database connection is successful because the isopen function returns 1. Otherwise, the database connection is closed.
%
% Create a MongoDB query to identify documents to remove. For this example, specify the employeedata collection. Create the MongoDB query to identify documents in the department that has the department identifier set to 80.

collection = "employeedata";
mongoquery = "{""department_id"":80}";

%
% Remove documents using the MongoDB query. The remove function removes three documents from the collection.

n = remove(conn,collection,mongoquery)

%
% Close the MongoDB connection.

close(conn)

% Copyright 2020 The MathWorks, Inc.