Skip to content

Unable to $push documents to array #41

Closed
@rms2219

Description

@rms2219

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions