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

Support for other types of ids #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

surfdude75
Copy link

I have a legacy mongo database where not all ids are of type ObjectId.

It would be great if the plugin could try do not use ObjectId if the id is not compatible with the ObjectID.

Thanks and congrats for you great work.

@StarpTech
Copy link
Member

Hi @surfdude75 thanks for your contribution. I understand your concern.

store.js Outdated
@@ -88,17 +88,23 @@ class MongoStore extends Store {
* @memberOf MongoStore
*/
removeById(req) {
var id
try {
id = this.ObjectID(req.id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of check is really bad. We can't trust in that an exception is thrown. Please check the format via regex and swap it out in a separate function to avoid duplicate code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is even better

var mongodb = require("mongodb"),
    objectid = mongodb.BSONPure.ObjectID;

console.log(objectid.isValid('53fbf4615c3b9f41c381b6a3'));

@surfdude75
Copy link
Author

Hi @StarpTech I hope it is as you requested.

Let me know if it is necessary any other adjustment.

Thanks.

@StarpTech
Copy link
Member

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

Successfully merging this pull request may close these issues.

2 participants