These are chat archives for reactioncommerce/reaction

1st
Feb 2017
Sam Tobia
@formula1
Feb 01 2017 00:22
I'm attempting to delete all variants in mongodb when the server starts but it is just returning false without calling my callback
function emptyOldVariants(productId) {
  var oldProducts = Products.find(query).fetch();
  console.log(oldProducts.length);
  console.log(Products.remove({}, {limit: 100}, function(err) {
    console.error("delete error:", err)
  }));
}
Sorry, Didn't mean to send that yet
Spencer Norman
@spencern
Feb 01 2017 00:22
Is this on the client or server?
Sam Tobia
@formula1
Feb 01 2017 00:23
server
function emptyOldVariants(productId) {
  var query = {
    ancestors: { $in: [productId] },
    type: "variant",
  };
  var oldProducts = Products.find(query).fetch();
  console.log(oldProducts.length);
  console.log(Products.remove(query, {limit: 100}, function(err) {
    console.error("delete error:", err)
  }));
}
More accurate example
I created some variants in the past
On server
Spencer Norman
@spencern
Feb 01 2017 00:27
Not sure if you can use the limit arg in a remove op
my guess is that’s causing the error
probably in Mongo
Sam Tobia
@formula1
Feb 01 2017 00:27
all try removing it
Spencer Norman
@spencern
Feb 01 2017 00:27
try passing IDs that you want to remove
Sam Tobia
@formula1
Feb 01 2017 00:28
nope
ok
Spencer Norman
@spencern
Feb 01 2017 00:29
you could use
const ids = Products.find(query, {limit: 100}).map(p => p._id)
and
Products.remove({_id: {$in: ids}})
or something similar
If that doesn’t work, try removing one item at a time by _id
Update: above code should probably be .find().fetch().map() not just .find().map()
Sam Tobia
@formula1
Feb 01 2017 00:33
also nothing
  var oldProducts = Products.find(query).fetch();
  console.log(oldProducts.length);
  oldProducts.forEach(function(product){
    Products.remove(product._id, function(err) {
      console.error("delete error:", err)
    })
  })
  oldProducts = Products.find(query).fetch();
Spencer Norman
@spencern
Feb 01 2017 00:34
weird.
Where is it returning false?
It might be possible that there’s something in Collection2 or Simple Schema that’s blocking your attempt too. A collection hook or something
Sam Tobia
@formula1
Feb 01 2017 00:36
I'll show what one looks like
Whats a keyword I should look for?
I tried allow
But Turned up nothing
I don't understand the permissions system here
Spencer Norman
@spencern
Feb 01 2017 00:38
Search for Products.before.remove
there’s some code there in startup.js
might be affecting
Sam Tobia
@formula1
Feb 01 2017 00:47
Yep, its defeninitely not being deleted
will it happen next iteration on the event loop
?
Spencer Norman
@spencern
Feb 01 2017 00:50
I’m not really sure exactly how the revisions system works tbh. I know it was implemented to allow people to “undelete” products and roll back changes, but I haven’t looked at the technical details yet. We turned it off for our system.
If it’s not something that will happen a lot you could just delete them from the mongo console
meteor mongo from a shell if you’re running locally
If you need it to be programmatic, @mikemurray is probably the best guy to answer
Sam Tobia
@formula1
Feb 01 2017 00:53
If I can use mongo --eval, I suppose thats fine
Sam Tobia
@formula1
Feb 01 2017 00:59
Though, doing it this way won't clean up revision files run hooks
Brent Hoover
@zenweasel
Feb 01 2017 02:08
You can use use Products.direct
Also, @mikemurray just showed me that if you delete a product (so that isDeleted is set to true and then delete it again it should actually delete
using direct will bypass hooks
Sam Tobia
@formula1
Feb 01 2017 02:11
Alright, I'll give it a go
perhaps I should update to be isDeleted then delete?
Because the double remove didn't seem to work
I'd prefer to go through hooks in case other Collections are dependent on the products
Brent Hoover
@zenweasel
Feb 01 2017 02:18
well, the reason we don’t allow you to delete is that if you have orders, or others you need to keep those products around
hrath2015
@hrath2015
Feb 01 2017 19:29
@jshimko need 1 quick info. What will be name of default mongodb instance to connect to when no MONGO_URL is not passed
in docker
Jeremy Shimko
@jshimko
Feb 01 2017 19:38
What do you mean by the name? The database name?
hrath2015
@hrath2015
Feb 01 2017 19:38
yes
what should be command to get into shell like docker exec -it mongodb $$$$
Jeremy Shimko
@jshimko
Feb 01 2017 19:39
reaction
docker exec -it containerName mongo reaction
hrath2015
@hrath2015
Feb 01 2017 19:40
thanks a lot
Jeremy Shimko
@jshimko
Feb 01 2017 19:40
sure
Sophie He
@sophiehe
Feb 01 2017 23:29
Catch a preview of v0.19.0! Join us tomorrow at 10am PST for the next Reaction Action livestream. Got questions for the team? Submit them here: http://ccst.io/e/reaction-action-february