Coder Social home page Coder Social logo

Comments (7)

bnoguchi avatar bnoguchi commented on August 11, 2024

This is done intentionally, due to the way mongodb treats unique indexes. mongoose-auth sets up email as a unique index, so you avoid scenarios where the same email can sign up twice. So we are forced to deal with the way that mongodb treats unique indexes. MongoDB itself (not mongoose itself) handles unique indexes in the following way:

If you were to save a User document with no email, then mongodb automatically fills it in with null. Mongodb treats nulls with the same unique index constraints, so if you try registering another user also e.g., via facebook, without saving an email, then mongodb will refuse to save it because you will just have tried to save a 2nd document that also has the email value null.

I chose to fill in a default value for the email field of "#{module_name}:#{unique_id_with_provider}", because that is unique across all documents and will not violate uniqueness constraints.

from mongoose-auth.

cayasso avatar cayasso commented on August 11, 2024

OK I got you, what about something like this as format 100000647911219@fb so I can parse the field like this (in case i ever need to)

var temp = "100000647911219@fb".split("@");
var tempId = temp[0];
var registeredFrom = temp[1];

At the same time is invalid email but its verbose "xxxxx number at facebook". I am not saying this is important but it makes a bit more sence in case someone want to do something crazy like knowing how much users from facebook hasn't register an email address.

I am just saying :-)

JB

from mongoose-auth.

bnoguchi avatar bnoguchi commented on August 11, 2024

In this case, it's better as the current colon delimited version. You can split on ":" if you need to. More importantly, because you lead with the source name instead of the provider uid, you can leverage mongodb's indexes for faster counting and lookup instead of doing the counting in the client or app.

from mongoose-auth.

cayasso avatar cayasso commented on August 11, 2024

Great point about leverage mongodb's indexes, I was thinking more about the extra space after the colon but I can live with that. Thank you Brian for your quick replies.

from mongoose-auth.

cayasso avatar cayasso commented on August 11, 2024

Ohh another thing just make sure you add all this great info to the README, for people to be aware and not bother you ;)

from mongoose-auth.

bnoguchi avatar bnoguchi commented on August 11, 2024

The extra space after the colon is a typo in my code. Will patch that.

from mongoose-auth.

cayasso avatar cayasso commented on August 11, 2024

Ahh ok nice! Thank you Brian.
Howdy from Costa Rica!

JB

from mongoose-auth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.