Question

What I have understood so far is that the mongoose needs us to define a schema. But what if my schema keeps changing on a per user basis. For instance, let's say there are thousands of users of mobile phones. Each user has a different kind of offer subscriptions and what nots. New offers keep coming, and he can even choose combos of offers, creating new offers on the fly. So these offers become keys holding sub documents of various other details regarding that offer. Such a schema can't be predefined. Shall I use mongoose then? Or stick to mongojs type thin-skin wrappers and forget about mongoose's ODM capabilities?

Was it helpful?

Solution

You could create a Mixed type schema where there's no restriction on the type of the data you can store. However, it comes at a trade-off. Take a look at the official documentation for info and implementation details.

OTHER TIPS

From the Mongoose docs:

NOTE: Any key/val set on the instance that does not exist in your schema is always ignored, regardless of schema option.

You can set the value when the model instance is created:

var task = new Task({'otherKey', 'some value'});

You could also put the ad-hoc values under a mixed subdocument type as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top