mongodb 连接方式之mongo-shell
单机连接:mongo 120.131.0.64:27017 -u root -p KingSoft@1314 --authenticationDatabase admin

字符串连接


python
import uuid
from pymongo import MongoClient
#两地址
CONN_ADDR1 = 'demotest-1.mongodb.tbc3.newtest.rdstest.aliyun-inc.com:27017'
CONN_ADDR2 = 'demotest-2.mongodb.tbc3.newtest.rdstest.aliyun-inc.com:27017'
REPLICAT_SET = 'mgset-1441984463'
username = 'demouser'
password = '123456'
#获取mongoclient
client = MongoClient([CONN_ADDR1, CONN_ADDR2], replicaSet=REPLICAT_SET)
#授权. 这里的user基于admin数据库授权
client.admin.authenticate(username, password)
#使用test数据库的collection:testColl做例子, 插入doc, 然后根据DEMO名查找
demo_name = 'python-' + str(uuid.uuid1())
print 'demo_name:', demo_name
doc = dict(DEMO=demo_name, MESG="Hello ApsaraDB For MongoDB")
doc_id = client.test.testColl.insert(doc)
print 'doc_id:', doc_id
for d in client.test.testColl.find(dict(DEMO=demo_name)):
print 'find documents:', d
pymongo
mongodb 连接方式之mongo-shell的更多相关文章
- MongoDB - Introduction of the mongo Shell
Introduction The mongo shell is an interactive JavaScript interface to MongoDB. You can use the mong ...
- 使用mongo shell和客户端连接至MongoDB Atlas
MongoDB Atlas是Mongo官方的一个集群服务,也可以注册并创建一个免费的集群,但DB的大小只有500M,如果数据量不是很大的应用,可以选择该集群方案 需要注意的是,目前我使用的这个集群,服 ...
- MongoDB基本增删改查操作-mongo shell
基础 1.查看所有数据库: show dbs 2.选择数据库: use test 3.查看数据库中有哪些集合: show collections 如下图: 查询 1.查看集合中有哪些数据,其中abc为 ...
- MongoDB error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js(转)
rror: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js 一般这种情况就是:自己指定的数据库,所以不能.自动加 ...
- MongoDB - The mongo Shell, mongo Shell Quick Reference
mongo Shell Command History You can retrieve previous commands issued in the mongo shell with the up ...
- MongoDB - The mongo Shell, Data Types in the mongo Shell
MongoDB BSON provides support for additional data types than JSON. Drivers provide native support fo ...
- MongoDB - The mongo Shell, Write Scripts for the mongo Shell
You can write scripts for the mongo shell in JavaScript that manipulate data in MongoDB or perform a ...
- MongoDB - The mongo Shell, Access the mongo Shell Help
In addition to the documentation in the MongoDB Manual, the mongo shell provides some additional inf ...
- MongoDB - MongoDB CRUD Operations, Query Documents, Iterate a Cursor in the mongo Shell
The db.collection.find() method returns a cursor. To access the documents, you need to iterate the c ...
随机推荐
- Go语言核心36讲(Go语言实战与应用十六)--学习笔记
38 | bytes包与字节串操作(上) 前导内容: bytes.Buffer基础知识 strings包和bytes包可以说是一对孪生兄弟,它们在 API 方面非常的相似.单从它们提供的函数的数量和功 ...
- 洛谷 P7156 - [USACO20DEC] Cowmistry P(分类讨论+trie 树上 dp)
题面传送门 题意: 给出集合 \(S=[l_1,r_1]\cup[l_2,r_2]\cup[l_3,r_3]\cup\dots\cup[l_n,r_n]\) 和整数 \(k\),求有多少个三元组 \( ...
- CF1553 部分题解
CF1553D Backspace 题目传送门. 题意简述:给定 \(s,t\),现在要依次输入 \(s\) 中的字符.对于每个字符 \(s_i\),你可以选择输入 \(s_i\) 或者使用退格键,判 ...
- NextPolish对基因组进行polish
NextPolish由未来组开发对基因组序列进行polish的工具,对三代以及二代均可进行polish. gituhp地址:https://github.com/Nextomics/NextPolis ...
- HMS Core Discovery直播预告 | AI画质增强 ,开启超清视界
[直播入口] B站华为开发者联盟:http://live.bilibili.com/22551651 4K.8K视频屡见不鲜,HD.FHD分辨率成小屏标配,当网络卡顿.视频自动切换到较低画质时,用户最 ...
- above, abrupt
above 近义词: over, beyond, exceeding反义词: below, beneath, under, underneath 有从右往左写的文字,没有从下往上的.above-men ...
- hadoop/spark面试题
总结于网络 转自:https://www.cnblogs.com/jchubby/p/5449379.html 1.简答说一下hadoop的map-reduce编程模型 首先map task会从本地文 ...
- Oracle—全局变量
Oracle全局变量 一.数据库程序包全局变量 在程序实现过程中,经常用遇到一些全局变量或常数.在程序开发过程中,往往会将该变量或常数存储于临时表或前台程序的全局变量中,由此带来运行效率降 ...
- k8s之ansible安装
项目地址:https://github.com/easzlab/kubeasz #:先配置harbor #:利用脚本安装docker root@k8s-harbor1:~# vim docker_in ...
- Android Bitmap 全面解析(二)加载多张图片的缓存处理
一般少量图片是很少出现OOM异常的,除非单张图片过~大~ 那么就可以用教程一里面的方法了通常应用场景是listview列表加载多张图片,为了提高效率一般要缓存一部分图片,这样方便再次查看时能快速显示~ ...