Upserting ‘rows’ mongodb

I have a remote processes that generate JSON objects and send them to a server that stores then in a MongoDB. I would like to store these objects in what I would call rows (coming from an SQL background) within a ‘master’ collection for example:

Results (Main Collection)

Results.Day
Results.Day.1.Data
Results.2
Results.Day.2.Data
etc

I am using an upsert because as the day proceeds some of the results will be regenerated by the remote processes so will need updating. At present I can upsert Results.Day.1 however when I attempt to upsert Results.Day.2 I get an error saying I have a duplicate key.

I am using the following query for my first upsert:

{ _id: ‘UUID’, Results.Day: { “$eq”: 1 } }

and for the second upsert:

{ _id: ‘UUID’, Results.Day: { “$eq”: 2 } }

Is it even possible to do this, and if so how can I do it? I would appreciate your thoughts on this. It is obvious I am no expert on NoSQL but from my limited understanding it would appear that I need to insert the ‘rows’ as arrays, but how I do this I do not know.

I have access to the source code to both the client and server so can change what is needed in order to accomplish this, so I would really appreciate help on this.

I am using for the Server

MongoDB v3.0.4 on Linux and the legacy-0.0-26compat c++ driver.
Windows 7 x64 and the same driver for the Client.


Source: c++

Leave a Reply