In my opinion, you may have to break down your requirement. I believe data should be saved in a way that can be accessed easily. For that will have to look at your requirements - how you plan to display or use data?
Anyway, I am sure that if I own 1000 objects it just does not make sense to see all at once. I would like to see in pages may be 10 per page or week by week or day by day.
Considering the above Let's look at this scenario.
- I own many documents.
- Last week I owned 2, yesterday 5, today 10 and list
goes own.
Suppose I own following docs.
Object1, Object2, Object5, Object6 ...
I will create an intermediate collection where I will store relationships, It will have one record per Object per day (or per hour - If need more granular search).
{
"_id": "someId",
"object": "Object1",
"year": 2015,
"month": 12,
"day": 1,
"hour": 12,
"owned_by": [
"stackyname",
"titogeo"
]
},
{
"_id": "someId",
"object": "Object2",
"year": 2015,
"month": 12,
"day": 1,
"hour": 12,
"owned_by": [
"antman",
"titogeo"
]
},
{
"_id": "someId",
"object": "Object2",
"year": 2015,
"month": 12,
"day": 2,
"hour": 13,
"owned_by": [
"batman",
"heman"
]
}
That means I have a relationship document per object per hour. When I own a document I push (upsert) my user id to the current relationship object. Current relationship object is
find({
"object": "object6",
"year": "currentYear",
"month": "currentMonth",
"hour" : "currentHour"
});
If I want all the users who own an object I can query relationship collection find({"object": "object6"})
(Of course with pagination).
If I want all documents that I own I can query find({'owned_by' : 'titogeo'})
I am not an expert in schema design nor I know the various technics. These are some thoughts I have and let me know yours.