mongoose field with the name type

node.jsMongoose

node.js Problem Overview


I am trying to validate and save a Passport profile with this structure:

http://passportjs.org/guide/profile/

This is the scheme I came up with:

// Define the schema.
schema = new mongoose.Schema({
	// The name of this user, suitable for display.
	displayName: String,
	// Each e-mail address ...
	emails: [{
		// ... with the actual email address ...
		value: String,
		// ... and the type of email address (home, work, etc.).
		type: String
	}],
	// A unique identifier for the user, as generated by the service provider.
	id: String,
	// The name ...
	name: {
		// ... with the family name of this user, or "last name" in most Western languages ...
		familyName: String,
		// ... with the given name of this user, or "first name" in most Western languages ...
		givenName: String,
		// ... and with the middle name of this user.
		middleName: String
	},
	// The provider which with the user authenticated.
	provider: String
});

The e-mail has a property called 'type', which is reserved for a mongoose type. How do I solve this?

node.js Solutions


Solution 1 - node.js

You need to define the field using an object:

type: {type: String}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDeathspikeView Question on Stackoverflow
Solution 1 - node.jsJohnnyHKView Answer on Stackoverflow