I have a Node.js application with a collection name drivers. In which I store these fields called carId, vendorId and clientId . All these are of type ObjectId, which is native to mongodb. Used to search, to which client and vendor a driver belongs. With these, I also store fields like. carName = Ford Mustang,carRegNo, vendorName and clientName . Which are more user friendly and people can directly Identify with them. Now I have two choices when I retrieve driver documents.
[{driverId : {carId , carName}}],[{driverId : {vendorId}}], [{driverId : clientId}] in array of objects and in cache like Redis and augment the response object to plug each field(vendorName, clientName,carName) into the response object. Thereby achieving the purposePros and Cons in my view
Which method is better I am unable to decide. If you have made a similar call in the past, probably you can help me make a better decision.
j
stuff ;)
it's the classic trade between spacecomplexity and timecomplexity the question is do you need them in runtime ? how do you invalidate the cache ? how is the lifecycle of an entry ? .... in doubt -> go for the database you can optimize later when you reach the problems and you save yourself the uncertain parts when you got metrics :)
that's at least my opinion -> just profile your system on regular basis and collect metrics so you can see what's pressing :)