DocumentationHelp Center
Determine if MongoDB connection is open
i = isopen(conn)
example
i = isopen(conn) returns 1 if the MongoDB® connection is open and 0 if it is closed.
conn
1
0
collapse all
Connect to MongoDB and count the total number of documents in a collection.
Create a MongoDB connection to the database mongotest. Here, the database server dbtb01 hosts this database using port number 27017.
mongotest
dbtb01
27017
server = "dbtb01"; port = 27017; dbname = "mongotest"; conn = mongo(server,port,dbname)
conn = mongo with properties: Database: 'mongotest' UserName: '' Server: {'dbtb01'} Port: 27017 CollectionNames: {'airlinesmall', 'employee', 'largedata' ... and 3 more} TotalDocuments: 23485919
conn is the mongo object that contains the MongoDB connection. The object properties contain information about the connection and the database.
mongo
The database name is mongotest.
The user name is blank.
The database server is dbtb01.
The port number is 27017.
This database contains six document collections. The first three collection names are airlinesmall, employee, and largedata.
airlinesmall
employee
largedata
This database contains 23,485,919 documents.
Verify the MongoDB connection.
isopen(conn)
ans = logical 1
The database connection is successful because the isopen function returns 1. Otherwise, the database connection is closed.
isopen
Determine the number of documents in the employee collection. There are 25 documents in the collection.
collection = "employee"; n = count(conn,collection)
n = 25
Close the MongoDB connection.
close(conn)
Verify the MongoDB connection is closed.
ans = logical 0
MongoDB connection, specified as a mongo object.
close | find | mongo
close
find
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office