Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
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
laravel-mongodb
Commits
1e533493
Commit
1e533493
authored
Sep 17, 2013
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed push and pull behaviour for #41
parent
94b99a0f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
25 deletions
+19
-25
README.md
README.md
+4
-4
Builder.php
src/Jenssegers/Mongodb/Builder.php
+0
-9
QueryBuilderTest.php
tests/QueryBuilderTest.php
+15
-12
No files found.
README.md
View file @
1e533493
...
@@ -276,17 +276,17 @@ Or you can access the internal object directly:
...
@@ -276,17 +276,17 @@ Or you can access the internal object directly:
**Push**
**Push**
Add
one or more
items to an array.
Add
an
items to an array.
DB::collection('users')->where('name', 'John')->push('items', 'boots');
DB::collection('users')->where('name', 'John')->push('items', 'boots');
DB::collection('users')->where('name', 'John')->push('
items', array('sword', 'shield
'));
DB::collection('users')->where('name', 'John')->push('
messages', array('from' => 'Jane Doe', 'message' => 'Hi John
'));
**Pull**
**Pull**
Remove
one or more values
from an array.
Remove
an item
from an array.
DB::collection('users')->where('name', 'John')->pull('items', 'boots');
DB::collection('users')->where('name', 'John')->pull('items', 'boots');
DB::collection('users')->where('name', 'John')->pull('
items', array('sword', 'shield
'));
DB::collection('users')->where('name', 'John')->pull('
messages', array('from' => 'Jane Doe', 'message' => 'Hi John
'));
**Unset**
**Unset**
...
...
src/Jenssegers/Mongodb/Builder.php
View file @
1e533493
...
@@ -458,11 +458,6 @@ class Builder extends \Illuminate\Database\Query\Builder {
...
@@ -458,11 +458,6 @@ class Builder extends \Illuminate\Database\Query\Builder {
{
{
$query
=
array
(
'$push'
=>
$column
);
$query
=
array
(
'$push'
=>
$column
);
}
}
else
if
(
is_array
(
$value
))
{
// $pushAll depricated
$query
=
array
(
'$push'
=>
array
(
$column
=>
array
(
'$each'
=>
$value
)));
}
else
else
{
{
$query
=
array
(
'$push'
=>
array
(
$column
=>
$value
));
$query
=
array
(
'$push'
=>
array
(
$column
=>
$value
));
...
@@ -484,10 +479,6 @@ class Builder extends \Illuminate\Database\Query\Builder {
...
@@ -484,10 +479,6 @@ class Builder extends \Illuminate\Database\Query\Builder {
{
{
$query
=
array
(
'$pull'
=>
$column
);
$query
=
array
(
'$pull'
=>
$column
);
}
}
else
if
(
is_array
(
$value
))
{
$query
=
array
(
'$pullAll'
=>
array
(
$column
=>
$value
));
}
else
else
{
{
$query
=
array
(
'$pull'
=>
array
(
$column
=>
$value
));
$query
=
array
(
'$pull'
=>
array
(
$column
=>
$value
));
...
...
tests/QueryBuilderTest.php
View file @
1e533493
...
@@ -196,7 +196,8 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
...
@@ -196,7 +196,8 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
{
{
$id
=
DB
::
collection
(
'users'
)
->
insertGetId
(
array
(
$id
=
DB
::
collection
(
'users'
)
->
insertGetId
(
array
(
'name'
=>
'John Doe'
,
'name'
=>
'John Doe'
,
'tags'
=>
array
()
'tags'
=>
array
(),
'messages'
=>
array
(),
));
));
DB
::
collection
(
'users'
)
->
where
(
'_id'
,
$id
)
->
push
(
'tags'
,
'tag1'
);
DB
::
collection
(
'users'
)
->
where
(
'_id'
,
$id
)
->
push
(
'tags'
,
'tag1'
);
...
@@ -213,19 +214,22 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
...
@@ -213,19 +214,22 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
2
,
count
(
$user
[
'tags'
]));
$this
->
assertEquals
(
2
,
count
(
$user
[
'tags'
]));
$this
->
assertEquals
(
'tag2'
,
$user
[
'tags'
][
1
]);
$this
->
assertEquals
(
'tag2'
,
$user
[
'tags'
][
1
]);
DB
::
collection
(
'users'
)
->
where
(
'_id'
,
$id
)
->
push
(
'tags'
,
array
(
'tag3'
,
'tag4'
));
$message
=
array
(
'from'
=>
'Jane'
,
'body'
=>
'Hi John'
);
DB
::
collection
(
'users'
)
->
where
(
'_id'
,
$id
)
->
push
(
'messages'
,
$message
);
$user
=
DB
::
collection
(
'users'
)
->
find
(
$id
);
$user
=
DB
::
collection
(
'users'
)
->
find
(
$id
);
$this
->
assertTrue
(
is_array
(
$user
[
'tags'
]));
$this
->
assertTrue
(
is_array
(
$user
[
'messages'
]));
$this
->
assertEquals
(
4
,
count
(
$user
[
'tags'
]));
$this
->
assertEquals
(
$message
,
$user
[
'messages'
][
0
]);
$this
->
assertEquals
(
'tag4'
,
$user
[
'tags'
][
3
]);
}
}
public
function
testPull
()
public
function
testPull
()
{
{
$message
=
array
(
'from'
=>
'Jane'
,
'body'
=>
'Hi John'
);
$id
=
DB
::
collection
(
'users'
)
->
insertGetId
(
array
(
$id
=
DB
::
collection
(
'users'
)
->
insertGetId
(
array
(
'name'
=>
'John Doe'
,
'name'
=>
'John Doe'
,
'tags'
=>
array
(
'tag1'
,
'tag2'
,
'tag3'
,
'tag4'
)
'tags'
=>
array
(
'tag1'
,
'tag2'
,
'tag3'
,
'tag4'
),
'messages'
=>
array
(
$message
)
));
));
DB
::
collection
(
'users'
)
->
where
(
'_id'
,
$id
)
->
pull
(
'tags'
,
'tag3'
);
DB
::
collection
(
'users'
)
->
where
(
'_id'
,
$id
)
->
pull
(
'tags'
,
'tag3'
);
...
@@ -235,12 +239,11 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
...
@@ -235,12 +239,11 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
3
,
count
(
$user
[
'tags'
]));
$this
->
assertEquals
(
3
,
count
(
$user
[
'tags'
]));
$this
->
assertEquals
(
'tag4'
,
$user
[
'tags'
][
2
]);
$this
->
assertEquals
(
'tag4'
,
$user
[
'tags'
][
2
]);
DB
::
collection
(
'users'
)
->
where
(
'_id'
,
$id
)
->
pull
(
'
tags'
,
array
(
'tag2'
,
'tag4'
)
);
DB
::
collection
(
'users'
)
->
where
(
'_id'
,
$id
)
->
pull
(
'
messages'
,
$message
);
$user
=
DB
::
collection
(
'users'
)
->
find
(
$id
);
$user
=
DB
::
collection
(
'users'
)
->
find
(
$id
);
$this
->
assertTrue
(
is_array
(
$user
[
'tags'
]));
$this
->
assertTrue
(
is_array
(
$user
[
'messages'
]));
$this
->
assertEquals
(
1
,
count
(
$user
[
'tags'
]));
$this
->
assertEquals
(
0
,
count
(
$user
[
'messages'
]));
$this
->
assertEquals
(
'tag1'
,
$user
[
'tags'
][
0
]);
}
}
public
function
testDistinct
()
public
function
testDistinct
()
...
...
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