略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: 链接服务器

2024-12-20

链接服务器

Table of Contents

链接到 mongo 服务器非常简单,只需要 new MongoClient,但是还可以改变更多的选项设置。 MongoClient::__construct() 方法的文档中包括了所有的 API 参数。这个页面给出了一些详细说明,和一些实用的案例。

add a note add a note

User Contributed Notes 3 notes

up
1
Anonymous
6 years ago
The whole part of persistent connections is outdated. In version 1.3.0:

«Removed the "persist" option, as all connections are now persistent. It can still be used, but it doesn't affect anything.»

As a matter of fact, this note is also wrong. Using option "persist" will throw an

Uncaught exception 'MongoConnectionException' with message '- Found unknown connection string option 'persist' with value 'x'
up
-8
daveg at smartbombinteractive dot com
6 years ago
I was getting "couldn't determine master" when trying to connect to a replica set.  It turns out there was a typo in my /etc/hosts entry for on of the replica set members.
up
-9
james at dunmore dot me dot uk
6 years ago
We've got a strange gotcha (it maybe a bug with the mongo driver and we will raise an appropriate bug with them), but I think this is worth noting here.....

We were connecting to a replica set, but always getting "couldn't determine master" being returned. Connecting to individual notes without replicaset being set worked fine (directly to the master, or slave okay for reads). Replicaset working fine, and all setup okay.

The issue was our network setup, despite being able to resolve dbname-X.domain.com the server names were returning as dbname-X without the domain.

Pinging dbname-X worked, but for some reason the driver isn't resolving it. Adding the entry to hosts fixed this though.

官方地址:https://www.php.net/manual/en/mongo.connecting.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3