0
test_cursor = db.command({
    "aggregate": "New_layout",
    "pipeline": [
        { "$match": { "$and": [
            { "FIRST_DATE": { "$gte": new_date } },
            { "CHAIN_ID": { "$ne": "" } }
        ] } },
        { "$unwind": { "path": "$ENTERS", "includeArrayIndex": "Date" } },
        { "$project": {
            "_id": 0,
            "SITE_ID": "$SITE_ID",
            "CHAIN_ID": "$CHAIN_ID",
            "SEGMENT_ID": "$SEGMENT_ID",
            "ZIP": "$ZIP",
            "ZIP3": "$ZIP3",
            "MARKET_ID": "$MARKET_ID",
            "REGION": "$REGION",
            "MALL_CODE": "$MALL_CODE",
            "MALL_AREA": "$MALL_AREA",
            "MALL_NAME": "$MALL_NAME",
            "FIRST_DATE": "$FIRST_DATE",
            "MARKET_AREA": "$MARKET_AREA",
            "REGION_AREA": "$REGION_AREA",
            "ZIP_AREA": "$ZIP_AREA",
            "ZIP3_AREA": "$ZIP3_AREA",
            "DATE": "$Date",
            "ENTERS": "$ENTERS"
        } }
    ],
    "allowDiskUse": bool(1),
    "cursor": {} 
})

asd=list(test_cursor)

The contents of the cursor are as below :-

 [u'cursor', u'ok', u'waitedMS'] .

However with an $out statement, the output collection has the expected contents. I am running pymongo v3.2.2 and mongo 3.2. I was told this problem is experienced with v3.0 or lesser, but this is something I am not able to figure out

chridam
  • 100,957
  • 23
  • 236
  • 235
Spartan07
  • 103
  • 1
  • 7

1 Answers1

0

You should use aggregate() instead of command().

test_cursor = db.New_layout.aggregate([
    { "$match": { "$and": [
        { "FIRST_DATE": { "$gte": new_date } },
        { "CHAIN_ID": { "$ne": "" } }
    ] } },
    { "$unwind": { "path": "$ENTERS", "includeArrayIndex": "Date" } },
    { "$project": {
        "_id": 0,
        "SITE_ID": "$SITE_ID",
        "CHAIN_ID": "$CHAIN_ID",
        "SEGMENT_ID": "$SEGMENT_ID",
        "ZIP": "$ZIP",
        "ZIP3": "$ZIP3",
        "MARKET_ID": "$MARKET_ID",
        "REGION": "$REGION",
        "MALL_CODE": "$MALL_CODE",
        "MALL_AREA": "$MALL_AREA",
        "MALL_NAME": "$MALL_NAME",
        "FIRST_DATE": "$FIRST_DATE",
        "MARKET_AREA": "$MARKET_AREA",
        "REGION_AREA": "$REGION_AREA",
        "ZIP_AREA": "$ZIP_AREA",
        "ZIP3_AREA": "$ZIP3_AREA",
        "DATE": "$Date",
        "ENTERS": "$ENTERS"
    } }
],
allowDiskUse=True)
helmy
  • 9,068
  • 3
  • 32
  • 31