taiyang2014

MongoDB安装

安装MongoDB: sudo python3 -m pip install pymongo
 
cd  /usr/local/Cellar/mongodb/3.4.4/bin
启动 mongoDB
1  cd .../bin  回车  ./mongod
2  cd …/bin  回车 ./mongo
 
 
 
mongod 失败解决方法:
ERROR: dbpath (/data/db) does not exist. Create this directory or give existing directory in –dbpath. See http://dochub.mongodb.org/core/startingandstoppingmongo
没有这个路径,需要创建/data/db这个目录
首先cd /
然后 sudo mkdir -p /data/db   创建/data/db
授权可读写操作的权限
sudo chown -R /data/db
 
 
//在终端中查询数据
show dbs
use taobao
db.getCollectionNames()
db.product1.find()
 
//在python中使用mongodb查询数据
'''
Created on 2017年5月22日
@author: edz
''’
import pymongo
client = pymongo.MongoClient('localhost')
db = client['taobao1']
 
for item in db.product1.find():
         print(item) 

posted on 2017-08-21 15:09  taiyang2014  阅读(147)  评论(0编辑  收藏  举报

导航