I have mongoDB with items of following structure:
{
"some_field": {
"date": 123,
"text": "secondary text"
},
"text": "primary text"
}
I want to write queries in pymongo that check for text field of top level and apply conditional query at the "date" field of second level. I'm getting filters of the form:
filter = {
"text": "some target text",
"date": {
"start": some_int_val1,
"end": some_int_val2
}
}
I can create query to "text" without any problem:
query = dict()
query["text"] = filter["text"]
But I'm stucked about how to construct an $and query on "some_field.date". I tried to simply combine them in one query:
query["somefield.date"] = [{"$gte": filter["common_date"]["start"]}, {"$lte": filter["common_date"]["end"]}]
But it didn't work. Also, I tried what I thought would work, but it throws an error:
query["somefield.date"] = { $and: [{"$gte": filter["date"]["start"]}, {: filter["date"]["end"]}]}
Saying "statement expected, found Py:AND_KEYWORD". How can I overcome this?