can any one explain meaning of mixed and buffer data type in mongoose ?
what is the exact use of mixed datatype in mongoose .Is there any way to store log data(containing both string and number.
Mixed. An "anything goes" SchemaType. Mongoose will not do any casting on mixed paths. You can define a mixed path using Schema.Types.Mixed or by passing an empty object literal. The following are equivalent.
Mongoose Buffer Schema type Buffer type is used when you usually work with items that get saved in binary form, a good example would be images.
MongoDB actually stores buffers in a special Binary class. A MongoDB binary is just a wrapper around a buffer with an additional sub_type property that is useful for UUIDs. For the purposes of this article though, you can ignore the sub_type property and just use the buffer property to get a Node. js buffer.
A Mongoose model is a wrapper on the Mongoose schema. A Mongoose schema defines the structure of the document, default values, validators, etc., whereas a Mongoose model provides an interface to the database for creating, querying, updating, deleting records, etc.
Mongoose MIX schema type
An "anything goes" SchemaType, its flexibility comes at a trade-off of it being harder to maintain. Mixed is available either through Schema.Types.Mixed or by passing an empty object literal. The following are equivalent:
var Any = new Schema({ any: {} });
var Any = new Schema({ any: Schema.Types.Mixed });
Since it is a schema-less type, you can change the value to anything else you like, but Mongoose loses the ability to auto detect/save those changes. To "tell" Mongoose that the value of a Mixed type has changed, call the .markModified(path) method of the document passing the path to the Mixed type you just changed.
person.anything = { x: [3, 4, { y: "changed" }] };
person.markModified('anything');
person.save(); // anything will now get saved
(original content taken from http://mongoosejs.com/docs/api.html#document_Document-markModified)
Mongoose Buffer Schema type
Buffer type is used when you usually work with items that get saved in binary form, a good example would be images.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With