In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
In this issue, the editor will bring you about the database commands in MongoDB. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
How do commands work?
Here's an example you're familiar with: drop. If you delete a collection from Shell, we run db.test.drop (). In fact, the drop command is executed internally, which is the same as the following with runCommand.
> db.runCommand ({"drop": "test"}); {"nIndexesWas": 1, "msg": "indexes dropped for collection", "ns": "test.test", "ok": true}
Ok indicates whether the execution was successful or not
In fact, mongoDB's command is implemented as a special query for a collection called $cmd, and runCommand only makes a query using parameters, so our drop can do the same.
Db.$cmd.findOne ({"drop": "test"})
When the mongoDB server receives a query for $cmd, it uses a special logic to handle it. Almost all drivers provide runCommand methods to execute commands, which can actually be done by executing queries.
Here are some of the most commonly used commands:
BuildInfo: {"buildInfo": 1}, returns the mongoDB server version and host operating system information collStats: {"collStats": collection}, and gives the statistical information of the specified collection, including the data size and the allocated storage control. Index size, such as distinct: {"distinct": collection, "key": key, "query": query} returns the value of all key that meet the query criteria in the specified collection drop: {"drop": collection}, delete collection said to have data dropDatabase: {"dropDatabase": 1}, delete all data in the current database dropIndexes: {"dropIndexes": collection, "index": name} Delete the index findAndModify named name on collection: see Chapter 3 getLastError: {"getLastError": 1 [, "w": W [, "wtimeout": timeout]]} to check the error or status information of the last operation on this connection. You can specify an option that this command will block until w salves replicates the last operation or the time expires (millisecond) isMaster: {"isMaster": 1} Check whether this server is master or slavelistCommands: {"listCommands": 1}, list all commands available on this server listDatabases: {"listDatabases": 1}, list all databases on the server ping: {"ping": 1}, check if the server is running, even if the server is locked this command will immediately return renameCollection: {"renameCollection": a, "to": B} Change the name of collection from a to brepairDatabase: {"repairDatabase": 1}, repair and compress the current database serverStatus: {"serverStatus": 1}, and get administrative statistics for this server.
These are the database commands in the MongoDB shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.