I am new to mongodb and got stuck on this task for some time now. I need to perform a query on the collection with the following schema:
{
ticker: String,
asks: [[Number]],
bids: [[Number]],
timestamp: String,
datetime: String
}
Here is the document example:
{
"_id" : ObjectId("5fc17630cf8dff0cd5506dc4"),
"asks" : [
[ "23685.0", "0.008" ],
[ "23688.8", "0.000" ],
[ "23696.7", "0.000" ]
],
"bids" : [
[ "23553.7", "0.200" ],
[ "23557.8", "0.207" ],
[ "23558.4", "0.045" ],
[ "23563.4", "0.020" ]
],
"timestamp" : 1606514176211,
"datetime" : "2020-11-27T21:56:16.211Z",
"ticker" : "YFI/USDT"
}
Inner array of asks and bids has two elements: first element is the price and the second element is the quantity.
I have two questions:
I need to query the collection to get all entries where price is greater than a value in both asks and bids ( only asks or only bids) for the time interval based on the datetime field. I tried to mess with $elemMatch and aggregate framework but had no luck so far.
Another question I have is whether array or arrays field type is a good choice when it comes to querying those fields. I expect to have millions of records of this type. Please suggest whether adding indexes and/or use some other data structure to hold this data in the collection.
Any help is greatly appreciated. Thanks.