MongoDB's authoritative guide to MongoDB basic Knowledge learning record

Source: Internet
Author: User
Tags bulk insert

Mongo

Show DBS View all databases

Using use, you can switch the database, and if there is no database, create a new

Use local to switch down the local database

Add data

Db.test.insert ({name: "Jack"}) inserts a piece of data into the test table, and if no test table is created, it is inserted in bulk if an array of documents is passed in.

BULK INSERT

Db.test.batchInsert ([{"_id": 0, "_id": 1}]) accepts an array of documents as a parameter, and if a document insertion fails during insertion, the document is inserted successfully before it and the document is not inserted.

After 3.4, I changed it.

Db.test.insertMany ()

Delete data

Db.test.remove ({name: "Jack"}) Delete all data in the test table named Jack

Find data

Db.test.find () View all data in test table

Db.test.findOne () View a single piece of data

modifying data

Db.test.update ({name: "Jack"}, {name: "Mike"}) change the data named Jack in the test table to name equals Mike

Db.test.save ({name: "Alice"}) creates a new data without the data, and then updates the

Linux creates a. Mongorc.js in the current user's home directory (/HOME/XXX).

MONGO the file is loaded before running the shell

You can override delete operations in a file to avoid deleting data

You can edit the variables in the shell after you specify editor= "/usr/bin/vim"

You can use a for loop to traverse the data in the shell

var collections = ["A", "B", "C"] for (var in collections) {    print ( Collections[i])}

A lot of the content has changed, please check the Official document address http://docs.mongoing.com/manual-zh/mongo.html

MongoDB's authoritative guide to MongoDB basic Knowledge learning record

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.