Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I do an update replacing all fields #159

Closed
jonascript opened this issue Mar 14, 2014 · 1 comment
Closed

How can I do an update replacing all fields #159

jonascript opened this issue Mar 14, 2014 · 1 comment

Comments

@jonascript
Copy link

Hello,
It seems there's no way using the query builder to do an update replacing all the fields so new object completely replaces the old document. It will just update the properties contained in the array passed to the update function leaving properties in the document that aren't in the array intact.

DB::connection('mongodb')
->collection($this->collectionName)
->where('_id', $id)
->update($insertArr)

http://docs.mongodb.org/manual/reference/method/db.collection.update/#example-update-replace-fields

Is there another way to do this using this lib or is this something that can be added in?

@jenssegers
Copy link
Contributor

The update method uses the set operator, so it's not possible at this moment. You can always perform raw operations: https://github.com/jenssegers/Laravel-MongoDB#raw-expressions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants