In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Installation mode
Use the apt-get install mongodb command directly, or install it with the source package.
Hadoop@dblab:/$ sudo apt-get update
Hadoop@dblab:/$ sudo apt-get install-y mongodb-org
Hadoop@dblab:/$ mongo-version
MongoDB shell version: 3.2.22
Hadoop@dblab:/$ sudo service mongodb start # launch MongoDB
Hadoop@dblab:/$ mongo # enters MongoDB Shell mode
> use school # switch to shcool database and create it automatically when you use it
Switched to db school
> db.createCollection ('teacher') # create a collection
{"ok": 1}
> show dbs # displays a list of databases
Local 0.000GB
School 0.000GB
> db.student.insert ({_ id:1,sname:'zhangsan',sage:20}) # insert data
WriteResult ({"nInserted": 1})
> db.student.insert ({_ id:2,sname:'lisi',sage:22}) # insert data
WriteResult ({"nMatched": 0, "nUpserted": 1, "nModified": 0, "_ id": 2})
> use school
Switched to db school
> show collections # displays the collection of the current database
Student
Teacher
# find data
> db.student.find () # find all records
{"_ id": 1, "sname": "lisi", "sage": 22}
{"_ id": 2, "sname": "lisi", "sage": 22}
> db.student.remove ({_ id: 2}) # Delete data
WriteResult ({"nRemoved": 1})
> db.student.find ()
{"_ id": 1, "sname": "lisi", "sage": 22}
> db.student.insert ({_ id:2,sname:'zhangsan',sage:25})
WriteResult ({"nInserted": 1})
> db.student.find ()
{"_ id": 1, "sname": "lisi", "sage": 22}
{"_ id": 2, "sname": "zhangsan", "sage": 25}
>
# modify data
> db.student.update ({_ id:2}, {$set: {sage:88}}, false,true)
WriteResult ({"nMatched": 1, "nUpserted": 0, "nModified": 1})
> db.student.find () .pretty ()
{"_ id": 1, "sname": "lisi", "sage": 22}
{"_ id": 2, "sname": "zhangsan", "sage": 88}
# Delete data
> db.student.remove ({sname:'lisi'})
WriteResult ({"nRemoved": 1})
# deleting a collection
> db.student.drop ()
> show collections
Teacher
> exit # exits MongoDB Shell mode
Bye
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.