MongoDB Common operations

Source: Internet
Author: User
Tags findone mongo shell

MongoDB is also a database, like MySQL, there are servers, databases, tables, records concepts. You can also use command operations in the terminal.

1. Connect MongoDB

MONGO 127.0.0.1:27017

2. Show all databases

Show DBS;

3. Using the Database

Use test;

4, view the database under the collection (table)

Show collections;

5. Manipulating a Collection

Db.person.find ();

6. View the database for the current operation

Db.getname ();

MongoDB execution JavaScript

MongoDB supports running JavaScript, which is basically the same as General JavaScript.

There are several ways to allow this:
1. Directly run the client in MongoDB connection. For example, edit and run JS in Robo 3T

2. MONGO--eval Run a script

Without entering interactive mode, run a MongoDB script directly under the command line of the OS.

Mongo127.0.0.1:27017/test--eval "Printjson (Db.users.findOne ())"

3, under the OS command line, run a JS file

MONGO 127.0.0.1:27017/testuserfindone.js

Content of Userfindone.js:

Printjson (Db.users.findOne ());

4, in MONGO Shell interactive mode, run a JS file

MONGO Test

Load ("/root/mongojs/userfindone.js")

MongoDB Common operations

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.