Home > Database > Mysql Tutorial > MongoDB的使用

MongoDB的使用

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:57:28
Original
1233 people have browsed it

最近项目用到了mongoDB,最近类mongoDB的Nosql数据库也比较火爆,把这个写下来,便于自己回顾和大家学习. 在mongoDB中数据的关系是database,collection,document 放到关系型数据库里面就是库,表,数据. 1.在ubuntu下执行 sudo apt-get install mongo 安装mongo.

最近项目用到了mongoDB,最近类似mongoDB的Nosql数据库也比较火爆,把这个写下来,便于自己回顾和大家学习.

在mongoDB中数据的关系是database,collection,document 放到关系型数据库里面就是库,表,数据.

1.在ubuntu下执行 sudo apt-get install mongo 安装mongo.

2.输入mongo进入数据库.

查看集合(表) show collections;

查看student集合的数据

db.student.find();

db.student.find().forEach(printjson);

查看第三条到第六条记录

db.student.find().skip(2).limit(3);

db.student.find().forEach(printjson); ---以json格式查看记录

向student集合中插入数据

db.student.insert({name:"Jack",age:22,score:86});

删除某条数据

db.student.remove({name:"Jack"});

修改数据

db.student.update({name:"Tom"},{$set:{name:"Lubby"}});

条件查询:

db.student.find({score:{$gt:86}}); score>86

db.student.find({score:{$gte:86}}); score>=86

db.student.find({score:{$lt:100}}); score

db.student.find({score:{$lte:100}}); score

db.student.find({score:{$gt:87,$lt:100}}); 87

db.student.find({name:{$ne:"Lubby"}}); name != Lubby

显示某个字段存在的数据

db.student.find({name:{$exists:true}});

查询不匹配 name=B*带头的记录
db.users.find({name: {$not: /^B.*/}});

正则表达式匹配

排序

db.student.find().sort({score:1}); 按照score升序排序

db.student.find().sort({score:-1}); 按照score降序排序

还有一些类似分组查询的回头有时间再补上.

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
mongodb start
From 1970-01-01 08:00:00
0
0
0
linux - ubuntu14 error installing mongodb
From 1970-01-01 08:00:00
0
0
0
Use of symfony2 mongodb
From 1970-01-01 08:00:00
0
0
0
mongodb _id rename
From 1970-01-01 08:00:00
0
0
0
Parameter understanding of mongodb
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template