In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 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.
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.