Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongoose field with the name type

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?

like image 344
Deathspike Avatar asked Feb 26 '13 21:02

Deathspike


People also ask

What is type in Mongoose?

type is a special property in Mongoose schemas. When Mongoose finds a nested property named type in your schema, Mongoose assumes that it needs to define a SchemaType with the given type.

What is the return type of Mongoose find?

find() function returns an instance of Mongoose's Query class. The Query class represents a raw CRUD operation that you may send to MongoDB. It provides a chainable interface for building up more sophisticated queries. You don't instantiate a Query directly, Customer.

What is __ V in MongoDB?

The __v field is called the version key. It describes the internal revision of a document. This __v field is used to track the revisions of a document. By default, its value is zero.

Why do we use Mongoose?

Mongoose is an Object Data Modeling (ODM) library for MongoDB and Node. js. It manages relationships between data, provides schema validation, and is used to translate between objects in code and the representation of those objects in MongoDB.


1 Answers

You need to define the field using an object:

type: {type: String} 
like image 181
JohnnyHK Avatar answered Sep 24 '22 04:09

JohnnyHK