In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Basic operation of MongoDB
The basic operation of MongoDB is mainly the operation of database, collection and document, including creating database, deleting database, inserting documents, changing documents, deleting documents, and querying documents.
Operation description show dbs View the list of databases under the current instance show users display user use toggle current database db.help () display database operation command show.collections display collection in the current database db.foo.help () display collection operation command Foo is a collection under the current database db.foo.find () data lookup for foo collections in the current database MongoDB data type MongoDB supports a list of many data types: String: this is the most commonly used data type to store data. The string in MongoDB must be a valid UTF-8. Integer: this type is used to store a value. Integers can be 32-bit or 64-bit, depending on your server. Boolean: this type is used to store a Boolean true/ false. Double: this type is used to store floating-point values. Min/ Max keys: this type is used to compare the lowest and highest values of the BSON element. Arrays: use this type of array or list or multiple values to store to a key. Timestamp: timestamp. This makes it easy to record when the file has been modified or added. Object: this data type is used for embedded files. Null: this type is used to store a null value. Symbol: this data type is the same for strings, but it is usually reserved for languages of specific symbol types. Date: this data type stores the UNIX time format of the current date or time. You can specify your own date and time, date and year, month, day to create the object. Object ID: this data type is used to store the ID of the document. Binary data: this data type is used to store binary data. Code: this data type is used for JavaScript code stored in a document. Regular expression: this data type is used to store regular tables # create a database testdb database, use the following statement mongos > use testdb;# to query the database, to show that the database must insert at least one document mongos > show dbs;# insert data document mongos > db.tablename.insert ({"name": "antian"}); # the database generates mongos > show dbs;testdb 0.078GB# query database mongos > show dbs;testdb 0.078GB# enters the database mongos > use testdb # Delete database mongos > db.dropDatabase (); {"dropped": "testdb", "ok": 1} # query database mongos > show dbs;# create collection # enter database mongos > use testdb;# create collection mongos > db.createCollection ("mycollection") mongos > show tables;mycollection# delete collection # enter database mongos > use testdb;mongos > show tables;mycollectionmongos > db.mycollection.drop (); truemongos > show tables # insert document # insert a document mongos > db.tablesname.insert ([{"name": "aaaaa", "age": "18"} # insert two documents mongos > db.tablesname.insert ([{"name": "ddddd", "age": "18"}, {"name": "eeee", "age": "10"}]); # query a document: mongos > db.tablesname.findOne (); MongoDB routine maintenance 1. Import and export
The mongoimport command imports the contents of a specific format file into a specified collection. The tool can import data in either JSON format or CSV format.
The mongoexport command exports a collection to a file in JSON format or CSV format. You can specify exported data items through parameters, or you can export data based on specified criteria.
Parameter description:
-d: specify the name of the database-c: indicate the name of collection-f: indicate which columns to export-o: indicate the name of the file to be exported-Q: indicate the filter condition for ("abc", "abc1") / / copy the database abc to generate abc1 IV. Clone collection
RunCommand
Clone the info collection in abc to instance 2
Mongo-- port 27018 / / enter the instance 2db.runCommand ({"cloneCollection": "abc.info", "from": "192.168.100.152 virtual 27017"}) five. Authorization start
Authorized users can be configured to access MongoDB, and auth=true must be specified at startup, otherwise authorization will not work.
Users can be added to roles, built-in database user roles include: read, readWrite, database management roles include: dbAdmin, dbOwner, useAdmin, superuser role is root.
Vim / usr/bin/mongodb1.conf.auth=true.mongo > use admin > db.createUser ({"zx": "root", "pwd": "123"," roles ":" [root "]}) / / create a user zx with a password of 123,assign to the root role > db.auth (" root "," 123") / / authenticate user 6. The command for process management to view currently running processes is: db.currentOp () to terminate running processes with high resource consumption: db.killOp (opid) 7.MongoDB monitoring to view database instance status information: db.serverStatus () to view current database statistics: db.status () to view collection statistics: db.users.stats () to view collection size: db.users.dataSize () ) you can also view system monitoring information through the Web interface You need to add the following line to the configuration file:
Httpinterface=true
Then access it through http://localhost:28017 in the browser. From the Web page, you can see:
Current MongoDB access statistics for all connections to each database and Collection, including: Reads, Writes, Queries, GetMores, Inserts, Updates, Removes. Write the last few hundred lines of the status log file of the lock. All MongoDB commands.
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.