Introduction: MongoDB comes with a JavaScript shell client, so it supports JavaScript syntax and most functions.
Introduction to MongoDB Common basic data types:
- NULL: null or non-existent field
- Boolean:true,false
- 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.
- String:
- Date: new Date (). GetTime ();//Gets the timestamp of the current time
- 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)