1.MongoDB是什么?
MongoDB(来自于英文单词“Humongous”,中文含义为“庞大”)是可以应用于各种规模的企业、各个行业以及各类应用程序的开源数据库。特别在大数据处理方面比较擅长。
2.bash命令
1.基本操作
mongo
exit
help
show dbs()
use blog;
db.dropDatabase()
db.stats()
2.操作集合
show collections()
db.createCollection("posts")
db.posts.renameCollection("articles")
db.articles.drop()
db.posts.find()
查看记录db.posts.count()
- insert()
db.posts.insert(
{ title:'第一篇博客',
content : "学习mongo",
tag : [ "未分类" ]
}
for(var i=2;i <=10; i++){
db.posts.insert(
title:'我的第'+i+'篇博客'
);
}
- remove()
db.posts.remove({})
db.posts.remove({title: "第2篇博客"})
3.带条件的文档db.find
db.posts.find({"tag":"name"})
db.posts.find({"rank":{$gte:2}})
db.posts.find({"rank":{$gt:2}})
db.posts.find({"rank":{$lte:4}})
db.posts.find({"rank":{$lt:4}})
db.posts.find({"title":/博客/})
db.posts.distinct("tag")
db.posts.find({"title":/博客/,"rank":{$gt:2}});
db.posts.find({$or: [{"title":/博客/},{"rank":{$gte:2}}] });
db.posts.find({"rank":{$in:[2,4]}});
db.posts.find({"isStop":{$exists:true}});