John Myers
2016-10-17 22:54:18 UTC
Hi,
I currently have very large collection with millions of documents, where
one field is the time of an event (in epoch seconds). All queries against
this collection will *at least* have this field present. There are some
other fields that can be included, depending on the application making the
query.
Example schema:
{
start: 1476744427,
sender: "Bob",
receiver: "Jane",
amount_sent: 45,
amount_received: 100
}
Let's say I want to support the following queries:
{$or: [{sender: "Bob", receiver: "Bob}], amount_sent: 30, start: {$gte:
12345, $lte: 5678}}
...
{start: {$gte: 12345, $lte: 5678}, amount_sent: 88}
If I need to sort, it will by most recent, so, descending.
The last one seems like I should just have an index on {start: -1,
amount_sent: 1} (or should it be amount_sent first??). My thought is that
if I use start as the first field in the compound index, other queries can
be supported, where other fields are searched on besides amount_sent, it
will just use the index to find the start times and then COLSCAN the rest.
For instance a query against "start" and "amount_received" can still
benefit from the index on start, but then have to scan for the
amount_received values.
Supporting the $or statement, I'm not sure, per the docs, each field in the
$or statement should have its own index, so do I need two here?
{start: -1, sender: 1} AND {start: -1, receiver: 1}
Thanks for any advice!
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/06a434f7-4760-414b-9d68-a2a23b9aafa2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I currently have very large collection with millions of documents, where
one field is the time of an event (in epoch seconds). All queries against
this collection will *at least* have this field present. There are some
other fields that can be included, depending on the application making the
query.
Example schema:
{
start: 1476744427,
sender: "Bob",
receiver: "Jane",
amount_sent: 45,
amount_received: 100
}
Let's say I want to support the following queries:
{$or: [{sender: "Bob", receiver: "Bob}], amount_sent: 30, start: {$gte:
12345, $lte: 5678}}
...
{start: {$gte: 12345, $lte: 5678}, amount_sent: 88}
If I need to sort, it will by most recent, so, descending.
The last one seems like I should just have an index on {start: -1,
amount_sent: 1} (or should it be amount_sent first??). My thought is that
if I use start as the first field in the compound index, other queries can
be supported, where other fields are searched on besides amount_sent, it
will just use the index to find the start times and then COLSCAN the rest.
For instance a query against "start" and "amount_received" can still
benefit from the index on start, but then have to scan for the
amount_received values.
Supporting the $or statement, I'm not sure, per the docs, each field in the
$or statement should have its own index, so do I need two here?
{start: -1, sender: 1} AND {start: -1, receiver: 1}
Thanks for any advice!
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/06a434f7-4760-414b-9d68-a2a23b9aafa2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.