Mongodb Study Notes 2 (simple addition, deletion, query, modification)-PHP source code

Source: Internet
Author: User
Tags findone
Mongodb Study Notes 2 (simple addition, deletion, query, and modification) 1. add a piece of data. I also practiced it yesterday, and today it is further consolidated. There are two main methods: save and insert. Example: db. blog. save ({"name": "taotao", "address": {"city": "beijing", "post": "100096"}, "phone ": "64645646"}) or db. blog. insert ({"name": "taotao", "address": {"city": "beijing", "post": "100096"}, "phone ": "15210340214 "})). In addition, you can assign values to a variable and insert the variable. For example
Post = {
... "Name": "taotao ",
... "Address ":{
... "City": "beijing ",
... "Post": "100096"
...},
... "Phone": "15210340214"
...}
Db. blog. insert (post );
2. delete a record db. set name. remove (condition); for example, db. blog. remove ({"name": "fe-"}) deletes the data whose name is
Deleting all records db. set name. remove (); deleting all records without any conditions is equivalent to deleting all data. For example, db. blog. remove ();
3. query all records db. set name. find (); for example, db. blog. find (); search all data in the collection lblog
Query all records of db. set name. findOne (condition), such as db. blog. findOne ({"name": "fe-"}), and query the data whose name is
This is a simple query. we will learn about various condition queries tomorrow.
4. modify record db. set name. update (condition); db. blog. update ({"name": "fe-" },{" name ":" taotao "}) it is reasonable to say that the conditions are not written and should be completely modified, however, the actual result is modified only by one.

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.