MongoDB / Pymongo Query with Datetime MongoDB / Pymongo Query with Datetime mongodb mongodb

MongoDB / Pymongo Query with Datetime


Repeating existing basic tutorial documentation:

start = datetime.datetime(2012, 2, 2, 6, 35, 6, 764)end = datetime.datetime(2012, 2, 2, 6, 55, 3, 381)for doc in db.wing_model.find({'time': {'$gte': start, '$lt': end}}):    print doc

Finally, why does the same query return different cursor object locations?

Where should that be the case?

You see two different cursor instances which will likely return the same result set - or?


@staticmethoddef _get_results_to_json(data):    """Get documents from a MongoDB search result.    Transforms MongoDB BSON documents into JSON serializable documents.    This process converts the ObjectIds into hexadecimal strings.    Parameters    ----------    data : `~pymongo.cursor.Cursor`        A MongoDB search result.    Returns    -------    |list| of |dict|        A list of JSON serializable documents.    """    if isinstance(data, Cursor):        data = list(data)    if isinstance(data, list):        for doc in data:            doc['_id'] = str(doc['_id'])    elif isinstance(data, dict):        data['_id'] = str(data['_id'])    return data_get_results_to_json(db.wing_model.find({'time': {'$gte': start, '$lt': end}}))