All Expiring Cards Report

Example in C#

var match1 = new BsonDocument("$match", 
			    new BsonDocument("$or", 
			    new BsonArray
			            {
			                new BsonDocument("_t", "Person"),
			                new BsonDocument("_t", "Attendee")
			            }));
	
var unwind1 = new BsonDocument("$unwind", 
			    new BsonDocument
			        {
			            { "path", "$CardAssignments" }, 
			            { "preserveNullAndEmptyArrays", true }
			        });

var match2 = new BsonDocument("$match", 
    new BsonDocument("$or", 
    new BsonArray
            {
                new BsonDocument("CardAssignments", 
                new BsonDocument("$exists", true)),
                new BsonDocument("Card", 
                new BsonDocument("$exists", true))
            }));

var match3 = new BsonDocument("$match", 
			    new BsonDocument("$or", 
				    new BsonArray
			        { 
						new BsonDocument("CardAssignments.ExpiresOn", new BsonDocument
			    		{
			        		{ "$gte", DateTime.UtcNow }, 
			        		{ "$lte", DateTime.UtcNow.AddYears(1) }
						}),
						new BsonDocument("Card.ExpiresOn", new BsonDocument
			    		{
			        		{ "$gte", DateTime.UtcNow }, 
			        		{ "$lte", DateTime.UtcNow.AddYears(1) }
						})
					}));

var project = new BsonDocument("$project", 
			    new BsonDocument
			        {
						{ "CommonName", 1 }, 
			            { "Card", 1 }, 
			            { "CardAssignments", 1 }, 
			            { "_id", 0 }
			        });
					
var bsonDocument = await client.AggregateAsync(currentInstance, "KeepObjects", new[] {match1,unwind1,match2,match3,project}, 30);

Example in CURL

curl -X POST \
  'https://keepapi.feenicshosting.com/api/f/INSTANCE_KEY_HERE/aggregate/KeepObjects?queryTimeout=30&jsonStrict=False%20' \
  -H 'Authorization: Bearer TOKEN_GOES_HERE' \
  -H 'Content-Type: application/json' \
  -d '["
        { 
            \"$match\" : 
            { 
                \"$or\" : 
                [
                    { \"_t\" : \"Person\" },
                    { \"_t\" : \"Attendee\" }
                ] 
            } 
        }","
        { \"$unwind\" : { \"path\" : \"$CardAssignments\", \"preserveNullAndEmptyArrays\" : true } }","
        { 
            \"$match\" : 
            {
                \"$or\" : 
                [
                    { \"CardAssignments\" : { \"$exists\" : true } },
                    { \"Card\" : { \"$exists\" : true } }
                ] 
            } 
        }","
        { 
            \"$match\" : 
            { 
                \"$or\" : 
                [
                    { \"CardAssignments.ExpiresOn\" : 
                        { \"$gte\" : ISODate(\"2019-06-12T19:51:37.23Z\"), \"$lte\" : ISODate(\"2020-06-12T19:51:37.231Z\") } },
                    { \"Card.ExpiresOn\" : 
                        { \"$gte\" : ISODate(\"2019-06-12T19:51:37.231Z\"), \"$lte\" : ISODate(\"2020-06-12T19:51:37.231Z\") } }
                ] 
            } 
        }","
        { 
            \"$project\" : 
            { 
                \"CommonName\" : 1, 
                \"Card\" : 1, 
                \"CardAssignments\" : 1, 
                \"_id\" : 0 
            } 
        }"
    ]'

Example Of Aggregate Used in JSON

[
    { 
        "$match" : 
        { 
            "$or" : 
            [
                { "_t" : "Person" },
                { "_t" : "Attendee" }
            ] 
        } 
    }","
    { "$unwind" : { "path" : "$CardAssignments", "preserveNullAndEmptyArrays" : true } }","
    { 
        "$match" : 
        {
            "$or" : 
            [
                { "CardAssignments" : { "$exists" : true } },
                { "Card" : { "$exists" : true } }
            ] 
        } 
    },
    { 
        "$match" : 
        { 
            "$or" : 
            [
                { "CardAssignments.ExpiresOn" : 
                    { "$gte" : ISODate("2019-06-12T19:51:37.23Z"), "$lte" : ISODate("2020-06-12T19:51:37.231Z") } },
                { "Card.ExpiresOn" : 
                    { "$gte" : ISODate("2019-06-12T19:51:37.231Z"), "$lte" : ISODate("2020-06-12T19:51:37.231Z") } }
            ] 
        } 
    },
    { 
        "$project" : 
        { 
            "CommonName" : 1, 
            "Card" : 1, 
            "CardAssignments" : 1, 
            "_id" : 0 
        } 
    }
]