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

Unable to $push documents to array #41

Closed
rms2219 opened this issue Sep 17, 2013 · 1 comment
Closed

Unable to $push documents to array #41

rms2219 opened this issue Sep 17, 2013 · 1 comment

Comments

@rms2219
Copy link

rms2219 commented Sep 17, 2013

I have a collection called "Contracts" with a field called "projects", which is an array of documents. Each document in the array would have an _id (a MongoID) and a 'projectName' (a string). I'm attempting to use the "push" function to append this array, but I cannot figure out how to add documents.

$projectId = new MongoId();
$test = DB::collection('Contracts')
            ->where('_id', $contractId)
            ->push('projects', array( '{ _id : '.$projectId.', projectName : <Project> }'));

The above code doesn't work, and I'm not sure how to do exactly what I'm trying to do. In addition, where I'm concatenating the $projectId, I really want that to be a new ObjectId.

How could I do this?
Thanks!

@jenssegers
Copy link
Contributor

I added an example to the readme for your question:

DB::collection('users')->where('name', 'John')->push('messages', array('from' => 'Jane Doe', 'message' => 'Hi John'));

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