Learning MONGO Series (ii) New database, collection, insert (), Save ()

Source: Internet
Author: User

Use user

Db

Show DBS

Db.dropdatabase ()

Db. Collection_name.insert (document)
Exp:
Db.user.insert ({name: "user1", Password: "123456"})
Hint: Writeresult ({"ninserted": 1}) indicates successful insertion
Db.user.find ()
Hint {"_id": ObjectId ("56946FBA3A18F4867AECBCD1"), "name": "user1", "Password": "
123456 "}
> test={name: "user2", Passsword: "123456"}
{"Name": "User2", "Passsword": "123456"}
> Db.user.insert (Test)
Writeresult ({"ninserted": 1})
> Db.user.find ()
{"_id": ObjectId ("56946FBA3A18F4867AECBCD1"), "name": "user1", "Password": "
123456 "}
{"_id": ObjectId ("5694714A3A18F4867AECBCD2"), "name": "User2", "Passsword":
"123456"}

Insert document You can also use the Db.col.save command. If you do not specify the _id field, the Save () method is similar to the Insert () method. If the _id field is specified, the data for the _id is updated.

Learning MONGO Series (ii) New database, collection, insert (), Save ()

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.