I am storing document in a nosql (mongo or others) datastore in json format like so
* edit start *
{
_id : 9182798172981729871
propertyBBBB: [
{
propertyCCCCC: "valueCCCC",
propertyDDDDD: [ "valueDDDD", "valueEEEE", "valueFFFF" ]
}, {
propertyCCCCC: "valueGGGG",
propertyDDDDD: [ "valueHHHH", "valueIIII", "valueFFFF" ]
}
....
]
}
.find( { _id : "9182798172981729871" } ,
{ propertyBBBB : { propertyDDDD : {"$elemMatch":{"$in":['refineaquerystringvar']}}}} )
**** edit end ****
Currently I am querying by _id and I perform logic on the nested array after the fetch has returned the document.
But I am looking for more flexibility in querying so I am thinking about making a new nosql (mongo or others) collection full of documents that look like the value of propertyBBBB
* edit start *
{
_id: 9234792837498237498237498
parentid: 9182798172981729871
propertyCCCCC: "valueCCCC",
propertyDDDDD: [ "valueDDDD", "valueEEEE", "valueFFFF" ]
}
{
_id: 9234792837498237498237497
parentid: 9182798172981729871
propertyCCCCC: "valueCCCC",
propertyDDDDD: [ "valueDDDD", "valueEEEE", "valueFFFF" ]
}
.find( { parentid : "9182798172981729871" } ,
{ propertyDDDDD : {"$elemMatch":{"$in":['refineaquerystringvar']}}} )
**** edit end ****
But I don't want to lose my query speed because in this way of doing things I am using more logic to query with parentid as a complimentary parameter instead of the main fetch. I am also fetching many objects instead of being sure that I am fetching one every time.
So my question is:
At what point is is better to query mongo by property instead of storing a large array inside of a document and querying that document _id? How big would the length of the array (or return query) be to make it more advantagious to use one convention over the other?