1.show dbs
2.db.tables.find()
3.use tablesnames;
4.db.dropDatabase();
5.db.collection.drop();
启动:mongod -f /etc/mongod.conf
附加配置文件
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
# network interfaces
net:
port: xxx
bindIp: 0.0.0.0 # Listen to local interface only, comment to listen on all interfaces.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
~
--------------------------------------------------------------------------
一、问题描述:
centos 7 上安装mongogdb,然后通过另外一台电脑用pymongo连接mongodb时,报错:连接拒绝
解决过程:
1、修改mongo.conf文件
命令:sudo vi /etc/mongo.conf
将原来bindIp:127.0.0.1 修改为0.0.0.0
(mongodb的配置文件中的bind_ip 默认为127.0.0.1,默认只有本机可以连接。 此时,需要将bind_ip配置为0.0.0.0,表示接受任何IP的连接。)
2、重启动mongo服务:service mongod restart
3、永久开放27017端口:
firewall-cmd –zone=public –permanent –add-port=27017/tcp; firewall-cmd –reload
(一定要加上firewall-cmd –reload,否则会失败)
---关于mogno 查询指令使用
. 大于,小于,大于或等于,小于或等于
$gt:大于
$lt:小于
$gte:大于或等于
$lte:小于或等于
例子:
db.collection.find({ "field" : { $gt: value } } ); // greater than : field > value
db.collection.find({ "field" : { $lt: value } } ); // less than : field < value
db.collection.find({ "field" : { $gte: value } } ); // greater than or equal to : field >= value
db.collection.find({ "field" : { $lte: value } } ); // less than or equal to : field <= value