My data look like this:
{
"_id" : ObjectId("60772a343d0e1058a8255145"),
"first" : ISODate("2010-01-01T18:00:00Z"),
"last" : ISODate("2010-01-01T18:55:00Z"),
"maxid13" : -9999,
"maxid9" : 7.9,
"minid13" : -9999,
"minid9" : 7.1,
"nsamples" : 12,
"samples" : [
{
"id1" : 3758,
"id6" : 2,
"id7" : -79.09,
"id8" : 35.97,
"id9" : 7.1,
"id10" : 0,
"id11" : -99999,
"id12" : 0,
"id13" : -9999,
"c14" : "U",
"id15" : 0,
"id16" : 62,
"id17" : 0,
"id18" : -99,
"id19" : -9999,
"id20" : 1199,
"id21" : 0,
"id22" : -99,
"id23" : 0,
"timestamp1" : ISODate("2010-01-01T18:00:00Z"),
"timestamp2" : ISODate("2010-01-01T13:00:00Z")
},
{
"id1" : 3758,
"id6" : 2,
"id7" : -79.09,
"id8" : 35.97,
"id9" : 7.2,
"id10" : 0,
"id11" : -99999,
"id12" : 0,
"id13" : -9999,
"c14" : "U",
"id15" : 0,
"id16" : 62,
"id17" : 0,
"id18" : -99,
"id19" : -9999,
"id20" : 1198,
"id21" : 0,
"id22" : -99,
"id23" : 0,
"timestamp1" : ISODate("2010-01-01T18:05:00Z"),
"timestamp2" : ISODate("2010-01-01T13:05:00Z")
},
.
.
.
I want to execute this query:
mydb1.mongodbbucketright.find(
{"samples.timestamp1": {"$gte": datetime.strptime("2010-01-01 00:05:00", "%Y-%m-%d %H:%M:%S"),
"$lte": datetime.strptime("2010-01-02 00:05:00", "%Y-%m-%d %H:%M:%S")},
"samples.id13":{"$gt":5}},
{"samples.$": 1 })
Is this the right way to find in nested documents?
I think get less results than usual.
Execution time is critical for me so i dont want to use aggregate if i can use find successfully.
With aggregate i can execute this query like this:
mydb1.mongodbbucketright.aggregate([
{
"$match": {
"first": {"$gte": datetime.strptime("2010-01-01 00:05:00", "%Y-%m-%d %H:%M:%S"),
"$lte" :datetime.strptime("2010-01-02 00:05:00", "%Y-%m-%d %H:%M:%S")},
"samples.id13": {"$gt": 5}
}
},
{ "$unwind": "$samples" },
{
"$match": {
"first": {"$gte": datetime.strptime("2010-01-01 00:05:00", "%Y-%m-%d %H:%M:%S"),
"$lte": datetime.strptime("2010-01-02 00:05:00", "%Y-%m-%d %H:%M:%S")},
"samples.id13": {"$gt": 5}
}
},
])
Which do you think is the right way?
Thanks in advance!