NoSQL Manager for MongoDB——MongoDBグラフィックス管理ツール

4838 ワード

ダウンロード先:https://www.mongodbmanager.com/download
CRUD操作
ショートカットキー:F 6カーソルがある文を実行し、F 5はすべての文を実行する
ドキュメントの挿入
/*
       
   db..insert();
*/

use test;

db.stus.insert({name:"tom",age:18,gender:"male"});

db.stus.insert([
    {name:"Oliver",age:36,gender:"male"},
    {name:"Siya",age:16,gender:"female"},
    {name:"John",age:26,gender:"male"},
    {name:"Alisi",age:21,gender:"female"}

]);

db.stus.find();



ドキュメントの変更
/*
       
   db..update();
*/

db.stus.find();

db.stus.update(
    {name:"tom"},
    {
      //      ,    ,     ,       
      //$set:{age:30,gender:"female"}

	 //      
       //$unset:{gender:1}

	//MongoDB             ,           
    //$set:{hobby:{cities:["beijing","shanghai"],movies:["hero","arrow"]}

	//$push              
	//$addToSet                 
	
	db.stus.update({name:"tom"},{$addToSet:{"hobby.cities":"hubei"}});
  
    },
    {multi:true} //            
 );



ドキュメントの照会
/*
       
   db..find();
*/

db.stus.find();   //      

db.stus.find({name:"tom"}); //find  name tom   ,    
db.stus.find({name:"tom"})[0].name;

db.stus.findOne({name:"tom"});//findOne     name tom   ,      
db.stus.findOne({name:"tom"}).name;


db.stus.find({name:"tom",age:20});  //  name tom    age 20   

db.stus.find().count();//         

ドキュメントの削除
/*
       
   db..remove();
*/

db.stus.find();

db.stus.remove({});  //        

db.stus.remove({name:"tom"});//             

db.stus.remove({name:"Siya"},true);//        true,            

db.stus.drop();  //    ,    remove   
show collections;

show dbs;
db.dropDatabase();



自己増加incremnet
//  inc

db.numbers.find();

db.numbers.updateMany(
{
  num:{$lte:100}
},
{
$inc:{num:10}
}
  

);

データおよびクエリーの一括追加
//      

var arr = [];

for(var i=1;i<40000;i++)
{
    arr.push({num:i});
}
db.numbers.insert(arr);

db.numbers.find();

db.numbers.drop();

//  numbers   num  500   
db.numbers.find({num:{$gt:500}});

//  
db.numbers.find({num:{$lt:500}});

//  40  50
db.numbers.find({num:{$gt:40,$lt:50}});

//    10   39000

db.numbers.find();

db.numbers.find({
    $or:[{num:{$lt:10}},{num:{$gt:39000}}]
    });

//       10   
db.numbers.find().limit(10);

//      11 20   ,skip       
db.numbers.find().skip(10).limit(10);

//21-30
db.numbers.find().skip(20).limit(10);

//MongoDB     skip limit   
db.numbers.find().limit(10).skip(20);

sort投影
//      _id      

db.numbers.find();

//sort()        ,-1  ,1  
//sort({  : ,  : });

db.numbers.find().sort({num:-1});

//find          
//0     
db.stus.find();
db.stus.find({},{_id:0,teacher_ids:0});

ドキュメント間の関係
/*
          
           
           /   
           
*/

//       users&&  orders

db.user.insert([{username:"gl"},{username:"wz"}]);

db.user.find();

db.user.drop();

db.orders.insert(
    [
    {
        list:["1","2","3"],
        user_id:ObjectId("5cfb88ca246f47af44c5c59b")
    },
    {
        list:["4","5","6"],
        user_id:ObjectId("5cfb88ca246f47af44c5c59b")
    },
    
     {
     list:["a","b","c"],
        user_id:ObjectId("5cfb88ca246f47af44c5c59c")
    },
    
     {
     list:["d","e","f"],
        user_id:ObjectId("5cfb88ca246f47af44c5c59c")
    },
    ]

);

db.orders.find();


var user_id = db.user.find({username:"gl"})[0]._id;
user_id

var user_id2 = db.user.find({username:"wz"})[0]._id;
db.orders.find({user_id:user_id2});


//       &&  

db.teacher.insert([
    {name:1},
    {name:2},
    {name:3}
    ]);

db.teacher.find();
db.teacher.drop();

db.stus.insert([
    {name:"A",
        teacher_ids:[ObjectId("5cfb8d7b246f47af44c5c5a5"),ObjectId("5cfb8d7b246f47af44c5c5a6")]
    },
   {name:"B",
   teacher_ids:[ObjectId("5cfb8d7b246f47af44c5c5a5"),ObjectId("5cfb8d7b246f47af44c5c5a6"),ObjectId("5cfb8d7b246f47af44c5c5a7")]
    },
    {name:"C",
        teacher_ids:[ObjectId("5cfb8d7b246f47af44c5c5a5")]
    }
]);

db.stus.drop();

db.stus.find();


//    A      

var arr = [];
arr[0] = db.stus.find({name:"A"})[0].teacher_ids[0];
arr[1] = db.stus.find({name:"A"})[0].teacher_ids[1];

db.teacher.find({_id:arr[0]});
db.teacher.find({_id:arr[1]});