1. Create a database:
> Use tutorialSwitched to DB tutorial <br/>
Here, you may have questions about how to use the tutorial database we have not created?
In fact, databases and collections are only created when document data is inserted for the first time.
Here we use the users set.
2. Insert a record:
> DB. Users. insert ({Username: "Smith "})
3. view records:
> DB. Users. Find ()
4. Insert the second record:
> DB. Users. Save ({Username: "Jones "})
5. view the number of records:
> DB. Users. Count ()
6. query all records:
> DB. Users. Find ()
7. Conditional query:
> DB. Users. Find ({Username: "Jones "})
8. Data Update (Smith's country is Canada)
> DB. Users. Update ({Username: "Smith" },{$ set: {country: "Canada "}})9. view the updated data:
> DB. Users. Find ({Username: "Smith "})
10. Remove attributes:
> DB. Users. Update ({Username: "Smith" },{$ unset: {country: 1 }})
11. Insert complex data:
> DB. users. update ({Username: "Smith" },</P> <p >{$ set: {favotites :{</P> <p> cities: ["Chicago ", "Cheyenne"], </P> <p> movies: ["Casablanca", "The Sting"] </P> <p >}< br/> })
Here we also update the Jones record.
> DB. users. update ({Username: "Jones" },</P> <p >{$ set: {favorites: </P> <p >{</P> <p> movies: ["Casablanca ", "Rocky"] </P> <p >}< br/>}) <br/>
12. query the internal object value:
> DB. Users. Find ({"favorites. Movies": "Casablanca "})
13. To add elements to the list, you can use $ push $ addtoset, where $ addtoset cannot be repeated, the third parameter can be ignored now, and the fourth Parameter
True indicates multiple updates:
> DB. users. update ({"favorites. movies ":" Casablanca "},</P> <p >{$ addtoset: {" favorites. movies ":" The Maltese Falcon "}}, false, true)
14. data deletion:
> DB. Users. Remove ({"favorites. Cities": "Cheyenne "})
15. delete a set:
> DB. Users. Drop ()