MongoDB C driver does not return any results for aggregation query <p>I have following SQL query:</p> <p>SELECT SUM("PAYMENT_HISTORY"."AMOUNT_PAID") FROM "PAYMENT_HISTORY" WHERE (("PAYMENT_HISTORY".YEAR >= 2011) AND ("PAYMENT_HISTORY".YEAR &lt;= 2013) AND ("PAYMENT_HISTORY"."AMOUNT_PAID" >= 500.0))</p> <p>same SQL after conversion was ran from MongoDB shell and it returns value.</p> <p>db.PAYMENT_HISTORY.aggregate( { $match : {$and: [{YEAR: {$gte : 2011}}, {YEAR: {$lte : 2013}}, {AMOUNT_PAID: {$gte: 500.00}}]}}, { $group : {_id : "POLICY_ID", total:{$sum : "$AMOUNT_PAID"}}} )</p> <p>While i am trying to run through MongoDB C driver, it doesn't return any results.</p> <pre><code>int status = mongo_client( mNoSQLConnection, "127.0.0.1", 27017 ); if (status != MONGO_OK){ switch (mNoSQLConnection-&gt;err) { case MONGO_CONN_NO_SOCKET: printf( "no socket\n" ); case MONGO_CONN_FAIL: printf( "connection failed\n" ); case MONGO_CONN_NOT_MASTER: printf( "not master\n" ); } } else{ bson query[1], b_result[1]; mongo_cursor cursor[1]; bson_init( query ); bson_append_string(query, "aggregate", "PAYMENT_HISTORY"); bson_append_start_object(query, "$match"); bson_append_start_array(query, "$and"); bson_append_start_object(query, "$gte"); bson_append_int(query, "YEAR", 2011); bson_append_finish_object(query); bson_append_start_object(query, "$lte"); bson_append_int(query, "YEAR", 2013); bson_append_finish_object(query); bson_append_start_object(query, "$gte"); bson_append_double(query, "AMOUNT_PAID", 500.00); bson_append_finish_object(query); bson_append_finish_array(query); bson_append_finish_object(query); bson_append_start_object(query, "$group"); bson_append_string(query, "_id", "POLICY_ID"); bson_append_string(query, "total", "total"); bson_append_start_object(query, "$sum"); bson_append_start_object(query, "$AMOUNT_PAID"); bson_append_finish_object(query); bson_append_finish_object(query); bson_append_finish_object(query); bson_finish( query ); bson_print(query); int status1; status1 = mongo_run_command(mNoSQLConnection, "DB_NAME", query, b_result); if (MONGO_OK != status1 ) { } else { /*command results*/ bson_print(b_result); } bson_destroy( query ); mongo_cursor_destroy( cursor ); } </code></pre> <p>Can somebody help me in figuring out mistake/s in above code?</p> <p>Thanks</p>