An example of the increase, deletion, modification and interpolation of MongoDB

Source: Internet
Author: User

Create a Student information sheet (at least includes: name, gender, score, age)

1. Write 15 different data

db.students.insertmany (
[
{name: "Bob", Age:16, Sex: "Male", grade:95},
{name: "Ahn", a ge:18, Sex: "Female", grade:45},
{name: "Xi", age:15, Sex: "Male", grade:75},
{name: "Bob1", age:16, Sex: "Ma Le ", grade:95},
{name:" Ahn1 ", age:18, Sex:" Male ", grade:45},
{name:" Xi1 ", age:15, Sex:" Female ", grade:55} ,
{name: "Bob2", age:16, Sex: "Female", grade:95},
{name: "Ahn2", age:18, Sex: "Male", grade:60},
{name: " Xi2 ", age:15, Sex:" Male ", grade:75},
{name:" Bob3 ", age:16, Sex:" Male ", grade:95},
{name:" Ahn3 ", age:18, S Ex: "Female", grade:45},
{name: "Xi3", age:15, Sex: "Male", grade:85},
{name: "Bob4", age:16, Sex: "Female", g RADE:95},
{name: "Ahn4", age:18, Sex: "Male", grade:45},
{name: "Xi4", age:15, Sex: "Male", grade:75}
]
)
2, query all male data (only the student's name and age)

Db.students.find ({sex: ' Male '}, {name:1, age:true, _id:0})


3. Information of students who have passed the exam (students score is greater than or equal to 60 points)


Db.students.find ({grade: {' $gte ': 60}})


4. Check the data of all 18-year-olds and 16-year-old girls


Db.students.find ({' $or ': [{sex: ' Male ', age:18}, {sex: ' Female ', Age:16}]})


5, according to the age of students to sort


Db.students.find (). Sort ({age:1})


6. Increase the age of all female students by one year


Db.students.update ({sex: ' female '}, {' $inc ': {age:1}}, {multi:true})

An instance of the increment, delete, change, and interpolate of MongoDB

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.