All Active Cards Report

Example in C#

var currentInstance  = await client.GetCurrentInstanceAsync();

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 )),
			new BsonDocument("Card.ExpiresOn", new BsonDocument("$gte", DateTime.UtcNow ))
			}));

var project = new BsonDocument("$project", 
			    new BsonDocument
			        {
						{ "CommonName", 1 }, 
			            { "Card", 1 }, 
			            { "CardAssignments", 1 }, 
			            { "_id", 0 }
			        });
					
var AllActiveCards = await client.AggregateAsync(currentInstance, "KeepObjects", new[] 

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:47:20.646Z\") } },
                    { \"Card.ExpiresOn\" : { \"$gte\" : ISODate(\"2019-06-12T19:47:20.646Z\") } }
                ] 
            } 
        }","
        { 
            \"$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:47:20.646Z") } },
                { "Card.ExpiresOn" : { "$gte" : ISODate("2019-06-12T19:47:20.646Z") } }
            ] 
        } 
    },
    { 
        "$project" : 
        { 
            "CommonName" : 1,
            "Card" : 1,
            "CardAssignments" : 1, 
            "_id" : 0 
        } 
    }
]