单机连接: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的更多相关文章

  1. MongoDB - Introduction of the mongo Shell

    Introduction The mongo shell is an interactive JavaScript interface to MongoDB. You can use the mong ...

  2. 使用mongo shell和客户端连接至MongoDB Atlas

    MongoDB Atlas是Mongo官方的一个集群服务,也可以注册并创建一个免费的集群,但DB的大小只有500M,如果数据量不是很大的应用,可以选择该集群方案 需要注意的是,目前我使用的这个集群,服 ...

  3. MongoDB基本增删改查操作-mongo shell

    基础 1.查看所有数据库: show dbs 2.选择数据库: use test 3.查看数据库中有哪些集合: show collections 如下图: 查询 1.查看集合中有哪些数据,其中abc为 ...

  4. 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 一般这种情况就是:自己指定的数据库,所以不能.自动加 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 主动扫描之Nmap

    主动扫描之Nmap 本文参考于李华峰等人的图书<Kali Linux2 网络渗透测试实践指南>2018年第1版 目录 主动扫描之Nmap 基本用法 主机发现 端口发现 扫描目标操作系统 扫 ...

  2. CF1575G GCD Festival

    \(\sum\sum gcd(i,j) \times gcd(a_i,a_j)\) 考虑枚举这个 \(gcd(i,j)\) . \(\sum_d \varphi(d)\sum_{i|d}\sum_{j ...

  3. [SDOI2012] Longge 的问题

    题意 求\(\sum_{i}^{n} gcd(i,n)\) 想法 套路题 \(\sum_{i}^{n} gcd(i,n)\) \(=\) \(\sum_{i,i | n} i * phi(n/i)\) ...

  4. AtCoder Regular Contest 127 题解

    sb atcoder 提前比赛时间/fn/fn/fn--sb atcoder 还我 rating/zk/zk/zk A 签到题,枚举位数 \(+\) 前导 \(1\) 个数然后随便算算贡献即可,时间复 ...

  5. 【Perl示例】整合多个文件

    这个需求是在生信分析中几乎天天用到,各种语言都能实现,也都各有特点.这次以perl为例. 已知 文件CT-VS-CON.All.xls为全部蛋白表达矩阵及其差异分析结果. 文件Homo_sapiens ...

  6. C语言小练习 微型学生管理系统

    很简陋,没有做输入校验,以写出来为第一目的,中间出了不少问题,尤其是结构体内字符串赋值的时候(理解不透彻),字符串比较用strcmp不能直接==判定,逻辑也很重要,不然会出现莫名其妙的问题. 涉及知识 ...

  7. Notepad++—显示代码对齐是使用了制表符还是空格

    使用Notepad++打开脚本,勾选"显示空格与制表符",此时你会看到代码对齐使用了制表符与空格 右箭头:TAB:空格:点: 参考:https://www.cnblogs.com/ ...

  8. fastboot烧写Andriod 以及SD 卡烧写LinuxQT,

    EMMC是一种FLASH,SD(TF)卡是另外的一种存储,通过控制拨码开关指引CPU去读EMMC还是SD卡的u-boot文件. u-boot的作用 初始化内存控制区,访问存储器,把内核从存储器读取出来 ...

  9. Redis - 1 - linux中使用docker-compose安装Redis - 更新完毕

    0.前言 有我联系方式的那些半吊子的人私信问我:安装Redis有没有更简单的方式,网上那些文章和视频,没找到满意的方法,所以我搞篇博客出来说明一下我的安装方式吧 1.准备工作 保证自己的linux中已 ...

  10. 如果通过 IP 判断是否是爬虫

    通过 IP 判断爬虫 如果你查看服务器日志,看到密密麻麻的 IP 地址,你一眼可以看出来那些 IP 是爬虫,那些 IP 是正常的爬虫,就像这样: 在这密密麻麻的日志里面,我们不仅要分辨出真正的爬虫 I ...