[SERVER-283] Push on objects in virtual collection Created: 06/Sep/09  Updated: 25/Apr/16  Resolved: 25/Apr/16

Status: Closed
Project: Core Server
Component/s: Usability
Affects Version/s: 1.0.0
Fix Version/s: None

Type: New Feature Priority: Minor - P4
Reporter: sandstrom Assignee: Unassigned
Resolution: Done Votes: 8
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-142 Read-only views over collection data. Closed
Participants:

 Description   

Support for this isn't implemented yet. (May be related to virtual collections.)

    1. preparation

use hej;
var a = {_id:1, question:"what is my name?", answers:[{_id:11, text:"its earl", comments:[{_id:111, text:"I agree"}]}]};
db.hej.save(a);

    1. query

db.hej.update({_id:1, "answers._id":11}, {"$push":{"answers.comments": {_id:112, text:"I dont agree"} }});

    1. error

> db.getLastError()
Modifier spec implies existence of an encapsulating object with a name that already represents a non-object, or is referenced in another $set clause

    1. notes


 Comments   
Comment by Ian Whalen (Inactive) [ 25/Apr/16 ]

Closing this as already having been implemented via $push against arrays. Please re-open if we've misunderstood the request.

Comment by Coen Hyde [ 15/Apr/10 ]

You can now do your query with a small modification. Just use the positional operator

db. hej.update({_id:1, "answers._id":11}, {"$push":{"answers.$.comments": {_id:112, text:"I dont agree"} } } );

Comment by Eliot Horowitz (Inactive) [ 08/Oct/09 ]

would have to be something like:

db.hej.$answers.update(

{ $parent : 1, _id:11 }

, {"$push" : { comments : {_id:112, text:"I dont agree" } } } )

Generated at Thu Feb 08 02:53:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.