Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can any one explain meaning of mixed and buffer data type in mongoose?

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.

like image 655
Vivin Prasannaa Avatar asked Jan 06 '17 16:01

Vivin Prasannaa


People also ask

What is mixed type in Mongoose?

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.

What is buffer data type in Mongoose?

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.

What is buffer data type in MongoDB?

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.

What is Mongoose model explain with example?

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.


1 Answers

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.

like image 101
satish chennupati Avatar answered Oct 06 '22 02:10

satish chennupati