前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MongoDB installation

MongoDB installation

原创
作者头像
vanguard
修改2021-01-28 16:04:48
4960
修改2021-01-28 16:04:48
举报
文章被收录于专栏:vanguardvanguardvanguard

MongoDB is a document database, which means it stores data in JSON-like documents. We believe this is the most natural way to think about data.

Mongodb installation - source code

# mongodb installation
# https://www.mongodb.com/download-center#community
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-4.2.3.tgz
tar zxvf mongodb-linux-x86_64-rhel62-4.2.3.tgz
# start
mkdir -p /data/mongodb
cd /usr/local/mongodb/bin
./mongod --port 27017 --dbpath=/data/mongodb
net start MongoDB
# check
./mongod --port 27017 --dbpath=/data/mongodb
./mongo -> use admin/XXX
# Python test
# yum install -y mongodb-server
pip install pymongo

MongoDB CRUD test - python

import pymongo
# connect
mclient = pymongo.MongoClient("mongodb://10.170.15.54:27017/")
print(mclient.list_database_names())
# create
test_db = mclient["helloworld"]
test_col = test_db["sites"]
x = test_col.insert_one({"name":"ELK","type":"NOSQL","url":"https://www.elkgroupinternational.com/elk-home"})
x = test_col.insert_one({"name":"MYSQL","type":"RELATION","url":"https://www.mysql.com"})
# update
test_query = { "name": "ELK" }
newvalues = {"$set":{"name":"MONGODB","type":"NOSQL","url":"https://www.mongodb.com"}}
test_col.update_one(test_query, newvalues)
# delete
test_query = { "name": "MYSQL" }
test_col.delete_one(test_query)
# retrive
print(test_col.find_one(),test_col.find())

installation

# download and installation
sudo apt-get install mongodb
# databse version
mongo -version

service

service mongodb start
service mongodb stop

configuration

/etc/mongodb.conf
# bind_ip = 0.0.0.0
# port = 27017
# auth = true

initialization

use hello_django
# insert one record
db.hello_django.insert({"question_text":"hello_django"})
show dbs

pip installation

# pymongo provide multi connections
pip install pymongo
# Django and MongoDB connection
pip install djongo

django settings

#  setting.py
DATABASES = {
    'default': {
        'ENGINE': 'djongo',
        'ENFORCE_SCHEMA': True,
        'NAME': 'hello_django',
        'CLIENT': {
            'host': '127.0.0.1',
        }
    }
}

operations

# entry
mongo
# status
db.stats()  
# databases
show dbs
# switch
use hello_django
# tables
show tables
# select * from polls_question
db.polls_question.find()
# exit

Done

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 MongoDB
腾讯云数据库 MongoDB(TencentDB for MongoDB)是腾讯云基于全球广受欢迎的 MongoDB 打造的高性能 NoSQL 数据库,100%完全兼容 MongoDB 协议,支持跨文档事务,提供稳定丰富的监控管理,弹性可扩展、自动容灾,适用于文档型数据库场景,您无需自建灾备体系及控制管理系统。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档