MongoDB集群怎样去访问?
上一章节简单介绍了MONGODB的集群搭建。相信大家都已经很熟悉了。集群搭建完接下来应该考虑我们的程序应该怎样去访问他。
怎么读写数据等操作。下面把我在工作中的一些用法列出来供大家作为参考。
官网的链接串格式如下:
mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]] 每一部分组成如下:
mongodb://
A required prefix to identify that this is a string in the standard connection format.
username:password@
Optional. If specified, the client will attempt to log in to the specific database using these credentials after connecting to the mongod instance. (如果设置了开启了安全验证需要加入用户名密码部分。如果没有开启auth=true。则不需要配置用户名和密码) 注意:在密码后面跟着一个@符号。可能是为了区分密码和后面的部分的分割。所以设置密码时候最好不要包含@。这样会导致mongodb默认读取第一个@符号之前的当作密码。 如果在密码中包含了密码该怎么处理呢。 在c#中只需要把密码中的@符号改成%40,在c#中自动转换为@了。
host1
This the only required part of the URI. It identifies a server address to connect to. It identifies either a hostname, IP address, or UNIX domain socket.
:port1
Optional. The default value is :27017 if not specified.
hostX
Optional. You can specify as many hosts as necessary. You would specify multiple hosts, for example, for connections to replica sets.
:portX
Optional. The default value is :27017 if not specified.
/database
Optional. The name of the database to authenticate if the connection string includes authentication credentials in the form of username:password@. If /database is not specified and the connection string includes credentials, the driver will authenticate to the admin database. 如果是集群。 database 应该为admin. 因为密码验证是在admin库中查询并验证的。 如果你设置的是你存储数据的数据库。 可能会出现用户不存在的错误。 这里需要注意下。
?options
Connection specific options. See Connection String Options for a full description of these options.
If the connection string does not specify a database/ you must specify a slash (i.e. /) between the last hostN and the question mark that begins the string of options.
实例:
mongodb://admin:212313@12.0.0.1:30000,12.0.0.2:30000,12.0.0.3:30000/admin?slaveOk=true;readPreference=secondary
用户名:administrator
密码:13579@$^*)
三个访问入口 mongos地址 : 12.0.0.1:30000,12.0.0.2:30000,12.0.0.3:30000
slaveOK=ture : 开启从库可读。(默认从库不可读写)
readPreference=secondary: 偏好读取从节点。 开启读写分离。 其他配置请参考官网。
更多内容:
2.用户权限怎么添加?
3.如何监控集群环境是否工作正常。
4.如何做到数据分布式存储
5.片键如何选择?
6.索引建立
7.curd基本操作。
8.读写分离如何控制。
9.c# php java js 等如何使用Mongod集群的?
针对上面问题。接下来会慢慢更新。
MongoDB集群怎样去访问?的更多相关文章
- mongodb3.6 (四)net 客户端如何连接、访问mongodb集群
前言 在是一篇文章mongodb如何做数据备灾 中已经介绍mongodb集群是如何工作,可能很多人都有这样一个疑问:客户端如何知道主服务挂了呢?这一篇文章将介绍如何在net中访问这个集群. 第一步.安 ...
- 搭建高可用mongodb集群(四)—— 分片(经典)
转自:http://www.lanceyan.com/tech/arch/mongodb_shard1.html 按照上一节中<搭建高可用mongodb集群(三)-- 深入副本集>搭建后还 ...
- [转]搭建高可用mongodb集群(四)—— 分片
按照上一节中<搭建高可用mongodb集群(三)—— 深入副本集>搭建后还有两个问题没有解决: 从节点每个上面的数据都是对数据库全量拷贝,从节点压力会不会过大? 数据压力大到机器支撑不了的 ...
- 搭建高可用mongodb集群(四)—— 分片
按照上一节中<搭建高可用mongodb集群(三)—— 深入副本集>搭建后还有两个问题没有解决: 从节点每个上面的数据都是对数据库全量拷贝,从节点压力会不会过大? 数据压力大到机器支撑不了的 ...
- 搭建高可用mongodb集群(四)—— 分片
按照上一节中<搭建高可用mongodb集群(三)-- 深入副本集>搭建后还有两个问题没有解决: 从节点每个上面的数据都是对数据库全量拷贝,从节点压力会不会过大? 数据压力大到机器支撑不了的 ...
- Mongodb集群节点故障恢复场景分析
http://blog.csdn.net/zhangzhaokun/article/details/6299527 一个适当配置的Mongodb分片集群是没有单点故障. 本文描述了分片集群中存在的几种 ...
- 搭建高可用mongodb集群—— 分片
从节点每个上面的数据都是对数据库全量拷贝,从节点压力会不会过大? 数据压力大到机器支撑不了的时候能否做到自动扩展? 在系统早期,数据量还小的时候不会引起太大的问题,但是随着数据量持续增多,后续迟早会出 ...
- MongoDB集群单mongos的问题总结
问题发现 在使用过程中,通过spark访问集群的效率不是很令人满意,80核心同时运行的速度比单核心也就快了20倍左右,预测瓶颈在mongodb读写上.当然,此时没遇到其他问题暂时没进行问题梳理. 在数 ...
- MongoDB集群运维笔记
前面的文章介绍了MongoDB副本集和分片集群的做法,下面对MongoDB集群的日常维护操作进行小总结: MongDB副本集故障转移功能得益于它的选举机制.选举机制采用了Bully算法,可以很方便从分 ...
随机推荐
- MySQL学习笔记(一):查询
查询实例: 1.创建数据库并使用: create database school; use school; 2.创建表并插入内容: create table student( Sno char(9) ...
- Liunux疑问
Liunux疑问 其中的各种软件的安装有模糊的点,待解决 待解决 待解决 待解决 ... ...
- HTML 培训教程
HTML培训教程 1. HTML概述 1.1. 什么是 HTML 文件? n ...
- 一个数字从后向前输入每一位数字,Camel和Pascal命名规范,IsValid()
int num = int.Parse(Console.ReadLine()); ; ) { n = num % ; num /= ; Console.WriteLine(n); } Camel和Pa ...
- Jenkins 更换国内源
jenkins插件清华大学镜像地址https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json1更换地址方法1.进入j ...
- 【DP】【构造】NOIp模拟题 演讲 题解
极其考思维的好题 题目背景 众所周知,$\mathrm{Zdrcl}$是一名天天$\mathrm{AK}$的高水平选手. 作为一民长者,为了向大家讲述自己$\mathrm{AK}$的经验,他决 ...
- 108th LeetCode Weekly Contest Unique Email Addresses
Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...
- Codeforces - 518D 概率DP初步
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #i ...
- 自动生成缓存Key值的CacheKeyHelper
/// <summary> /// CacheKeyHelper /// </summary> public class CacheKeyHelper { /// <su ...
- springboot(五)-使用Redis
Redis服务器 springboot要使用redis,首先当然要确保redis服务器能够正常跑起来. pom.xml 这里添加redis的依赖,当然也是springboot集成好的. <!-- ...