Skip to content
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

Remove deleteMany not working #38

Open
gmahe opened this issue Jun 24, 2019 · 0 comments
Open

Remove deleteMany not working #38

gmahe opened this issue Jun 24, 2019 · 0 comments

Comments

@gmahe
Copy link

gmahe commented Jun 24, 2019

Looking at https://github.com/db-migrate/mongodb/blob/master/index.js#L337 the deleteMany method is not going to work.

We check if options is an array if(util.isArray(options)) and then add it in the query.

case 'remove':
  // options is the records to insert in this case
  if(util.isArray(options))
    db.collection(collection).deleteMany(options, callbackFunction);
  else
    db.collection(collection).deleteOne(options, callbackFunction);
  break;

The issue is filter from deleteMany(filter) is expected to be an object and not an array and will return an error: MongoError: BSON field 'delete.deletes.q' is the wrong type 'array', expected type 'object'

Here the code I was using:

db._run("remove", "pets3", { id: "003" }, callback); // This removes one entry.
db._run("remove", "pets3", [{ id: "003" }], callback); // This fails obviously.

// This code works and it's using directly the mongo instance.
const getDbInstance = await db._run("getDbInstance");
getDbInstance.collection("pets3").deleteMany({ id: "003" }); // This removes every entries.
getDbInstance.close();

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant