Dan
Dan

Reputation: 314

Write a query in MongoDB's client pymongo that converts a part of the string to a date on the fly

So basically I have this collection where objects are stored with a string parameter. example:

{"string_": "MSWCHI20160501"}

The last part of that string is a date, so my question is this: Is there a way of writing a mongo query which will take that string, convert part of it into an IsoDate object and then filter objects by that IsoDate.

p.s I know I can do a migration but I wonder if I can achieve that without one.

Upvotes: 2

Views: 78

Answers (1)

lesingerouge
lesingerouge

Reputation: 1168

Depending on the schema of your objects, you could hypothetically write an aggregation pipeline that would first transform the objects, then filter the results based on the results and then return those filtered results.

The main reason I would not recommend this way though is that, given a fairly large size for your dataset, the aggregation is going to fail because of memory problems.

And that is without mentioning the long execution time for this command.

Upvotes: 1

Related Questions