記錄下平常的MongoDB操做命令:html
//新建庫
use iceportal_imagemongodb
//新建collection
db.createCollection("xxx-acc",{autoIndexId : true}) ;
db.createCollection("xxx-img",{autoIndexId : true}) ;xcode
//插入數據
db.getCollection("xxx-img").insert(
{_id:ObjectId(),
xxId:"xxx21749",
caption:"GT",
nameZh:"大唐",
nameEn:"xs",
category:"xss",
xxxCode:"STSSW",
url:"/xme/bb",
imageName:"xss",
extension:".jpg",
specs:"12x15",
isDefault:"1",
publicId:"64556",
fileHashCode:"32666",
isDeleted:"1",
createTime:ObjectId("5349b4ddd2781d08c09890f4").getTimestamp(),
updateTime:ObjectId("5349b4ddd2781d08c09890f4").getTimestamp()
}
)xss
db.getCollection("xxx-acc").insert(
{_id:ObjectId(),
accId:"1",
xxxId:"xxx21749",
accType:"GT",
createTime:ObjectId("5349b4ddd2781d08c09890f4").getTimestamp(),
updateTime:ObjectId("5349b4ddd2781d08c09890f4").getTimestamp()
}
)url
//查看collection
show collectionsexcel
//mongo經常使用查詢語句
//查詢數據
db.getCollection("xxx-acc").find({})
.projection({})
.sort({_id:-1})
.limit(100)code
//mongodb正則查詢
db.xxx201907.find({'_id':{$regex:'xxxA22097'}});
db.xxx201907.find({"availDate":{ "$gte":("2019-06-20 0:0:0")}}).count()
db.getCollection("xxx-filter-2019-10").find({
_id: "xxx_2019-10"
});htm
//統計一下xxx庫有多少bbID,而後將獲得的數據所有放入excel中排重
db.xxx201906.distinct( "bbID",{"availDate":{ "$gte":("2019-06-20 0:0:0")}})
db.xxx201907.distinct( "bbID" );
db.xxx201908.distinct( "bbID" );
db.xxx201909.distinct( "bbID" );
db.xxx201910.distinct( "bbID" );
db.xxx201911.distinct( "bbID" );
db.xxx201912.distinct( "bbID" );
db.xxx202001.distinct( "bbID" );
db.xxx202002.distinct( "bbID" );
db.xxx202003.distinct( "bbID" );
db.xxx202004.distinct( "bbID" );
db.xxx202005.distinct( "bbID" );
db.xxx202006.distinct( "bbID" );教程
//複雜清理腳步編寫
db.xxx201908.find({xxxId:"xxx50181",xxxcode:"CQ",xxxrcode:"xxBAWC"}).forEach(function(b){
var x_id=b._id;
//print(_id);
var xxxId=b.xxxId;
var xxxcode=b.xxxcode;
var xxxrcode=b.xxxrcode;
var availDate=b.availDate;
var x=xxxId+"-"+xxxcode+"-"+xxxrcode+"-"+availDate;
//print(x);
if(x_id!=x){
print(x_id);
//db.xxx201908.remove({_id:x_id});
}
});rem
//刪除庫
db.dropDatabase()
//刪除集合
db.collection.drop()
//刪除一條數據
db.collection.remove({'title':'MongoDB 教程'})
//刪除 一條數據
db.getCollection("xxx-acc").remove({'_id':ObjectId("5d5763c61e541088a85bbb43")})
參考文檔:mongo文檔https://www.runoob.com/mongodb/mongodb-create-database.html