Life Thunder Dog MongoDB----MONGODB---2---common commands and tricks

Source: Internet
Author: User

To see which databases are available:

Show DBS

Switch to that library:

Use library name

 Use Local

Use also has a function of "Create a Database"

 Use test

To delete a database:

Db.dropdatabase ();

To view a collection:

Show collections

To create a collection:

Db.createcollection ("user");

Implicitly created, inserted directly into the collection, she will automatically create the collection

Db. user. Insert ({ID:1, Name: "Lisi"});

To delete a collection:

Db. user. Drop ();

Insert:

Db. user. Insert ({ID:1, Name: "Lisi", Sex: "1"});

Inquire:

Db. user. Find ()

Modify:

Db. user. Update ({ID:1},{name:'Lisi', Sex:'1'});

Delete:

Db. user. Remove ({name:'Lisi'});

If you insert two identical parameters at the same time, they will be overwritten by the following

Db. user. Insert ({x:2, x:3});

It's strictly case-sensitive in MongoDB.

If you want to make time a non-string form in real-world development, you can insert data by using the new date method:

Db. user. Insert ({name:'Lisi', Addtime:new Date ()});

If the direct date () is created as a string, the

If you do not want to see him print out the default generated heap of _id strings at the time of printing, we can query by the following methods:

Db. user. Find ({},{_id:0});

If _id:1 then print out the default _id

Life Thunder Dog MongoDB----MONGODB---2---common commands and tricks

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.