In mongo shell my query work fine, but with meteor no, why?
for example
update(
{
"_id": “ckhSJ5zmbT4JLL2w8”,
},
{ “$pull”: { “orders”: { “id”: “tm4RuXwgYQSK6wpfz” } } }
)
i use SimpleSchema, and autoform. any body help?
In mongo shell my query work fine, but with meteor no, why?
for example
update(
{
"_id": “ckhSJ5zmbT4JLL2w8”,
},
{ “$pull”: { “orders”: { “id”: “tm4RuXwgYQSK6wpfz” } } }
)
i use SimpleSchema, and autoform. any body help?
what means "with meteor no"
does it result in error? result of 0 updated, or what exactly ?
and SimpleSchema can stop u from doing that if result does not match the required structure/format…
@shock nailed it - we need more details to help you troubleshoot. Unless of course your example is just not working because you meant to use _id
instead of id
for your orders match.
true.
The $pull operator definitely works in Meteor. To see it working:
Create a brand new meteor project: meteor create mongo-pull-test
Replace all generated files with these 2 files:
mongo-pull-test.html:
<head>
<title>mongo-pull-test</title>
</head>
<body>
<h1>mongo-pull-test</h1>
<h2>Cars</h2>
{{#with garage}}
{{#each cars}}
{{this}}
{{/each}}
{{/with}}
<button>Goodbye Hyundai</button>
</body>
mongo-pull-test.js:
Garage = new Mongo.Collection('garage');
if (Meteor.isClient) {
Template.body.helpers({
garage() {
return Garage.findOne();
}
});
Template.body.events({
'click button': () => {
const garage = Garage.findOne();
Garage.update({ _id: garage._id }, {
$pull: {
cars: 'Hyundai'
}
});
}
});
}
if (Meteor.isServer) {
Meteor.startup(() => {
if (!Garage.find().count()) {
Garage.insert({ cars: [ 'Ford', 'Honda', 'Hyundai' ] });
}
});
}
Click the “Goodbye Hyundai” button and $pull will remove it from Mongo.