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
7cf94542
Commit
7cf94542
authored
Dec 01, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'v1.0'
parents
6faa8907
c1590fa4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
28 deletions
+36
-28
Collection.php
src/Collection.php
+36
-28
No files found.
src/Collection.php
View file @
7cf94542
...
@@ -42,6 +42,7 @@ class Collection
...
@@ -42,6 +42,7 @@ class Collection
'root'
=>
'MongoDB\Model\BSONDocument'
,
'root'
=>
'MongoDB\Model\BSONDocument'
,
];
];
private
static
$wireVersionForFindAndModifyWriteConcern
=
4
;
private
static
$wireVersionForFindAndModifyWriteConcern
=
4
;
private
static
$wireVersionForReadConcern
=
4
;
private
static
$wireVersionForWritableCommandWriteConcern
=
5
;
private
static
$wireVersionForWritableCommandWriteConcern
=
5
;
private
$collectionName
;
private
$collectionName
;
...
@@ -169,13 +170,6 @@ class Collection
...
@@ -169,13 +170,6 @@ class Collection
{
{
$hasOutStage
=
\MongoDB\is_last_pipeline_operator_out
(
$pipeline
);
$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'
]))
{
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
$options
[
'readPreference'
]
=
$this
->
readPreference
;
}
}
...
@@ -184,12 +178,21 @@ class Collection
...
@@ -184,12 +178,21 @@ class Collection
$options
[
'readPreference'
]
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
$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'
]))
{
if
(
!
isset
(
$options
[
'typeMap'
])
&&
(
!
isset
(
$options
[
'useCursor'
])
||
$options
[
'useCursor'
]))
{
$options
[
'typeMap'
]
=
$this
->
typeMap
;
$options
[
'typeMap'
]
=
$this
->
typeMap
;
}
}
$server
=
$this
->
manager
->
selectServer
(
$options
[
'readPreference'
]);
if
(
$hasOutStage
&&
!
isset
(
$options
[
'writeConcern'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForWritableCommandWriteConcern
))
{
if
(
$hasOutStage
&&
!
isset
(
$options
[
'writeConcern'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForWritableCommandWriteConcern
))
{
$options
[
'writeConcern'
]
=
$this
->
writeConcern
;
$options
[
'writeConcern'
]
=
$this
->
writeConcern
;
}
}
...
@@ -236,17 +239,18 @@ class Collection
...
@@ -236,17 +239,18 @@ class Collection
*/
*/
public
function
count
(
$filter
=
[],
array
$options
=
[])
public
function
count
(
$filter
=
[],
array
$options
=
[])
{
{
if
(
!
isset
(
$options
[
'readConcern'
]))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
if
(
!
isset
(
$options
[
'readPreference'
]))
{
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
$options
[
'readPreference'
]
=
$this
->
readPreference
;
}
}
$operation
=
new
Count
(
$this
->
databaseName
,
$this
->
collectionName
,
$filter
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
$options
[
'readPreference'
]);
$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
);
return
$operation
->
execute
(
$server
);
}
}
...
@@ -374,17 +378,18 @@ class Collection
...
@@ -374,17 +378,18 @@ class Collection
*/
*/
public
function
distinct
(
$fieldName
,
$filter
=
[],
array
$options
=
[])
public
function
distinct
(
$fieldName
,
$filter
=
[],
array
$options
=
[])
{
{
if
(
!
isset
(
$options
[
'readConcern'
]))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
if
(
!
isset
(
$options
[
'readPreference'
]))
{
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
$options
[
'readPreference'
]
=
$this
->
readPreference
;
}
}
$operation
=
new
Distinct
(
$this
->
databaseName
,
$this
->
collectionName
,
$fieldName
,
$filter
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
$options
[
'readPreference'
]);
$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
);
return
$operation
->
execute
(
$server
);
}
}
...
@@ -490,20 +495,21 @@ class Collection
...
@@ -490,20 +495,21 @@ class Collection
*/
*/
public
function
find
(
$filter
=
[],
array
$options
=
[])
public
function
find
(
$filter
=
[],
array
$options
=
[])
{
{
if
(
!
isset
(
$options
[
'readConcern'
]))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
if
(
!
isset
(
$options
[
'readPreference'
]))
{
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
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'
]))
{
if
(
!
isset
(
$options
[
'typeMap'
]))
{
$options
[
'typeMap'
]
=
$this
->
typeMap
;
$options
[
'typeMap'
]
=
$this
->
typeMap
;
}
}
$operation
=
new
Find
(
$this
->
databaseName
,
$this
->
collectionName
,
$filter
,
$options
);
$operation
=
new
Find
(
$this
->
databaseName
,
$this
->
collectionName
,
$filter
,
$options
);
$server
=
$this
->
manager
->
selectServer
(
$options
[
'readPreference'
]);
return
$operation
->
execute
(
$server
);
return
$operation
->
execute
(
$server
);
}
}
...
@@ -522,14 +528,16 @@ class Collection
...
@@ -522,14 +528,16 @@ class Collection
*/
*/
public
function
findOne
(
$filter
=
[],
array
$options
=
[])
public
function
findOne
(
$filter
=
[],
array
$options
=
[])
{
{
if
(
!
isset
(
$options
[
'readConcern'
]))
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
if
(
!
isset
(
$options
[
'readPreference'
]))
{
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
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'
]))
{
if
(
!
isset
(
$options
[
'typeMap'
]))
{
$options
[
'typeMap'
]
=
$this
->
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