ubuntu安装mongo数据库

安装mongo数据库,在shell下输入

sudo apt-get install mongodb

如果需要在Python中使用mongo数据库,还需要额外安装Python封装库

pip install pymongo

 检测安装是否成功,可以使用下面命令在本地启动MongoDB

mongod -dbpath .

在shell中输入mongo,就可以进入mongo数据库

查询数据库语句

> show databases;
cache	0.0625GB
local	0.03125GB

使用数据库语句 

> use cache;
switched to db cache

建立一个叫做webpage的table

db.createCollection('webpage')

查询全部table语句

> show tables;
system.indexes
webpage

 查询talbe中的内容

db.webpage.find();

 查询某些列的语句

db.webpage.find({},{_id:0})    #0代表不显示,1代表显示

 查询特定行的语句

db.webpage.find({ID:"XXX"})

 查询最后一条数据

db.baidutag.find({}).sort({"_id":-1}).limit(1)

 Mongo数据导出

mongoexport -d local -c baidutagtemp -o /home/mi/baidutag.csv --csv -f "title,author,ablum,tag,category,genre"

 添加过滤条件

mongoexport -d local -c wangyiartist -o /home/common/下载/huayuartist.csv --csv -f "artist_name,artist_type,artist_id" -q '{artist_type:"欧美男歌手"}'

 多个条件

mongoexport -d local -c wangyiartist -o /home/common/下载/huayuartist.csv --csv -f "artist_name,artist_type,artist_id" -q '{"$or":[{artist_type:"华语女歌手"},{artist_type:"华语男歌手"}]}'
原文地址:https://www.cnblogs.com/tonglin0325/p/6284286.html