MongoDB Learning Notes (i)

Source: Internet
Author: User
Tags bulk insert

Introduction: MongoDB comes with a JavaScript shell client, so it supports JavaScript syntax and most functions.

Introduction to MongoDB Common basic data types:

    1. NULL: null or non-existent field
    2. Boolean:true,false
    3. Numeric type: The default value type in MongoDB is double, you can use the Numberint () function and the Numberlong () function to specify a field as Integer and Long Integer, respectively.
    4. String:
    5. Date: new Date (). GetTime ();//Gets the timestamp of the current time
    6. Array: Var uarray=["Zhang San", "John Doe", "Harry"];

MongoDB Basic Operations

Add Data:   

Monomer Insert:

var p1 ={    "name": "Zhang Jie"    ,"age": Numberint ("" "),//  The default value type in MongoDB is double    "sex":false}db.user.insert (p1);
View Code

BULK INSERT:

1. Insert an array directly:

 var  p2=[{ "name": "Zhang Jie"   Age: Numberint ("
   
    // 
        In MongoDB, the value type defaults to double  "sex": 
    false  
     " { "name": "Li Na" 
    " age ": Numberint (" "), // mongodb default is double  "sex": true
       "name": "RMB" ,  "age ": Numberint (" "), // mongodb defaults to double  "Sex": true  }]db.user.insert (p2);  
   
View Code

2. Circular Insertion

varP2=[    {        "Name": "Li Chen",        "Age": Numberint ("28"),//the value type in MongoDB defaults to double"Sex":false    },    {        "Name": "Deng Chao",        "Age": Numberint ("33"),//the value type in MongoDB defaults to double"Sex":false    },    {        "Name": "Zheng Kai",        "Age": Numberint ("28"),//the value type in MongoDB defaults to double"Sex":false    }] for(vari=0;i<p2.length;i++) {Db.user.insert (p2[i]);}
View Code

Delete data

Delete all documents in the user collection:

Db.user.remove (); // Delete all documents in the user collection
View Code

To delete the specified collection:

var where={    "name": "Zheng Kai"};d B.user.remove (where); // Delete all documents with "name" as "Zheng Kai" in the user collection
View Code

Delete a collection directly

Db.user.drop (); // Delete User Collection
View Code

MongoDB Learning Notes (i)

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.