-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
Update $pull an object from [Object]? #284
Comments
I'm experiencing the same behaviour, have you manage to get it resolved? |
No, unfortunately I never did resolve that issue. Instead I had to On Sat, May 7, 2016 at 1:00 AM, stewiegaribaldi [email protected]
|
Thank you for your reply rtcwp07, in my case it was my subdocument has auto value, so I need to do
|
Ah I see now! Great information, thanks. On Wed, May 11, 2016 at 2:49 AM, stewiegaribaldi [email protected]
|
Have the same problem, can set and push but not pull This finds the element: This updates it: This does NOT pull it: |
Ooops, ignore my previous comment. I got the query wrong, this works: it needs to know what to pull... |
Closing old issues. Please comment if this is still an issue and should be reopened. |
@aldeed I prepared it in Meteor (1.6.0) but probably similar results can be observed using just npm packages. import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
s = new SimpleSchema({
'things': {
type: Array,
},
'things.$': {
type: Object,
},
'things.$.name': {
type: String,
},
'things.$.valid': {
type: Boolean,
optional: true,
defaultValue: true,
},
});
Hello = new Mongo.Collection('absolutelyFilledWithThings');
Hello.attachSchema(s);
Hello.insert({'things': [{
'name': 'yep',
'valid': true, // Note: The schema defaultValue for this property is also `true`
}, {
'name': 'sure',
'valid': true,
},
]});
Hello.update(
{},
{$pull: {'things': {'valid': 'cute-kitten'}}}, // Note: This shouldn't match anything
{'multi': true}
); // Expected outcome: No changes, all inserted entries have a two-element `things` array
console.dir(Hello.find().fetch(), {'depth': 3});
// After the update is executed, however, all DB entries will have `things: []` (empty array!) |
Haven't had a chance to look yet, but I'll reopen for now |
I can confirm I am having this problem and struggling to find a workaround. |
First of all I want to say thank you for providing these awesome packages, and I hope I'm asking this in the right place! Using Simple Schema and collection2, having trouble pulling one object from an array of objects. For a trivia game app, using $push to add new players is working fine, but for the life of me I can't figure out how to remove a particular player from the doc when they leave the game. Here's the schema:
I've tried every permutation of every schema variable and update method that I know is possible, including:
where
playerToPull
is the whole player object, right from the doc.5) $set method, as:
where
newPlayers
is a splice of the original players array without the player object that I'm trying to remove.Nothing I've tried has resulted in a successful update. Am I missing something obvious? Thanks for your help!
The text was updated successfully, but these errors were encountered: