Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does mongoDB4.0 operate the database

2025-05-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces mongoDB4.0 how to operate the database, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

MongoDB4.0 database

Download: https://www.mongodb.com/

Installation: slightly

Note: modify the configuration file mongodb.cfg under the bin directory before use, and delete the 'mp' field in the last line

1. Start service and terminate service

Net start mongodbnet stop mongodb

two。 Create an administrator user

Mongouse admindb.createUser ({user: "yxp", pwd: "997997", roles: ["root"]})

3. Use the account password to connect to mongodb

Mongo-u adminUserName-p userPassword-- authenticationDatabase admin

4. Database

View the database

Show dbs

Switch database

Use db_name

Add database

Db.table1.insert ({'astatri1}) create a database (switch to the database to insert tables and data)

Delete database

Db.dropDatabase () delete database (switch before deletion)

5. Table

Switch the database before using it

View tabl

Show tables, check all the tables.

Add table

Use library db.table1. Insert ({'breadghill 2}) add tables (created if the table does not exist)

Delete tabl

Db.table1.drop () delete the table

6. data

Increase data

Db.test.insert ({'name':'mac'}) insert one db.user.insertMany ([{}, user2,user3,user4,user5]) insert multiple strips

Delete data

Db.user.deleteOne ({'age': 8}) delete the first matching db.user.deleteMany ({' addr.country': 'China'}) delete all matching db.user.deleteMany ({}) delete all

View data

Db.user.find ({'name':'alex'}) check is equivalent to where xx==xxdb.user.find ({' name': {"$ne": 'alex'}}) check xxxdb.user.find ({' _ id': {'$gt':2}}), check xx > xxdb.user.find ({"_ id": {"$gte": 2,}), check xx > = xxdb.user.find ({'_ id': {'$lt':3}}), check xx

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report