Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
4c61d3c5
Commit
4c61d3c5
authored
Nov 14, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-228: ReadConcern default should only be set when supported by the server
parent
3c742f3c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
27 deletions
+36
-27
Collection.php
src/Collection.php
+36
-27
No files found.
src/Collection.php
View file @
4c61d3c5
...
...
@@ -40,6 +40,7 @@ class Collection
'root'
=>
'MongoDB\Model\BSONDocument'
,
];
private
static
$wireVersionForFindAndModifyWriteConcern
=
4
;
private
static
$wireVersionForReadConcern
=
4
;
private
$collectionName
;
private
$databaseName
;
...
...
@@ -162,13 +163,6 @@ class Collection
{
$hasOutStage
=
\MongoDB\is_last_pipeline_operator_out
(
$pipeline
);
/* A "majority" read concern is not compatible with the $out stage, so
* avoid providing the Collection's read concern if it would conflict.
*/
if
(
!
isset
(
$options
[
'readConcern'
])
&&
!
(
$hasOutStage
&&
$this
->
readConcern
->
getLevel
()
===
ReadConcern
::
MAJORITY
))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
}
...
...
@@ -177,12 +171,22 @@ class Collection
$options
[
'readPreference'
]
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
}
$server
=
$this
->
manager
->
selectServer
(
$options
[
'readPreference'
]);
/* A "majority" read concern is not compatible with the $out stage, so
* avoid providing the Collection's read concern if it would conflict.
*/
if
(
!
isset
(
$options
[
'readConcern'
])
&&
!
(
$hasOutStage
&&
$this
->
readConcern
->
getLevel
()
===
ReadConcern
::
MAJORITY
)
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForReadConcern
))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
if
(
!
isset
(
$options
[
'typeMap'
])
&&
(
!
isset
(
$options
[
'useCursor'
])
||
$options
[
'useCursor'
]))
{
$options
[
'typeMap'
]
=
$this
->
typeMap
;
}
$operation
=
new
Aggregate
(
$this
->
databaseName
,
$this
->
collectionName
,
$pipeline
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
$options
[
'readPreference'
]);
return
$operation
->
execute
(
$server
);
}
...
...
@@ -217,17 +221,18 @@ class Collection
*/
public
function
count
(
$filter
=
[],
array
$options
=
[])
{
if
(
!
isset
(
$options
[
'readConcern'
]))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
}
$operation
=
new
Count
(
$this
->
databaseName
,
$this
->
collectionName
,
$filter
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
$options
[
'readPreference'
]);
if
(
!
isset
(
$options
[
'readConcern'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForReadConcern
))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
$operation
=
new
Count
(
$this
->
databaseName
,
$this
->
collectionName
,
$filter
,
$options
);
return
$operation
->
execute
(
$server
);
}
...
...
@@ -329,17 +334,18 @@ class Collection
*/
public
function
distinct
(
$fieldName
,
$filter
=
[],
array
$options
=
[])
{
if
(
!
isset
(
$options
[
'readConcern'
]))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
}
$operation
=
new
Distinct
(
$this
->
databaseName
,
$this
->
collectionName
,
$fieldName
,
$filter
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
$options
[
'readPreference'
]);
if
(
!
isset
(
$options
[
'readConcern'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForReadConcern
))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
$operation
=
new
Distinct
(
$this
->
databaseName
,
$this
->
collectionName
,
$fieldName
,
$filter
,
$options
);
return
$operation
->
execute
(
$server
);
}
...
...
@@ -419,20 +425,21 @@ class Collection
*/
public
function
find
(
$filter
=
[],
array
$options
=
[])
{
if
(
!
isset
(
$options
[
'readConcern'
]))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
}
$server
=
$this
->
manager
->
selectServer
(
$options
[
'readPreference'
]);
if
(
!
isset
(
$options
[
'readConcern'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForReadConcern
))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
if
(
!
isset
(
$options
[
'typeMap'
]))
{
$options
[
'typeMap'
]
=
$this
->
typeMap
;
}
$operation
=
new
Find
(
$this
->
databaseName
,
$this
->
collectionName
,
$filter
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
$options
[
'readPreference'
]);
return
$operation
->
execute
(
$server
);
}
...
...
@@ -448,14 +455,16 @@ class Collection
*/
public
function
findOne
(
$filter
=
[],
array
$options
=
[])
{
if
(
!
isset
(
$options
[
'readConcern'
]))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
}
$server
=
$this
->
manager
->
selectServer
(
$options
[
'readPreference'
]);
if
(
!
isset
(
$options
[
'readConcern'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForReadConcern
))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
if
(
!
isset
(
$options
[
'typeMap'
]))
{
$options
[
'typeMap'
]
=
$this
->
typeMap
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment