public IList <Entry> Get(IEnumerable <IKey> identifiers) { if (!identifiers.Any()) { return(new List <Entry>()); } IList <IKey> identifiersList = identifiers.ToList(); var versionedIdentifiers = GetBsonValues(identifiersList, k => k.HasVersionId()); var unversionedIdentifiers = GetBsonValues(identifiersList, k => k.HasVersionId() == false); var queries = new List <IMongoQuery>(); if (versionedIdentifiers.Any()) { queries.Add(GetSpecificVersionQuery(versionedIdentifiers)); } if (unversionedIdentifiers.Any()) { queries.Add(GetCurrentVersionQuery(unversionedIdentifiers)); } IMongoQuery query = MonQ.Query.Or(queries); MongoCursor <BsonDocument> cursor = collection.Find(query); return(cursor.ToEntries().ToList()); }
public IList <Entry> Get(IEnumerable <string> identifiers, string sortby) { var clauses = new List <IMongoQuery>(); IEnumerable <BsonValue> ids = identifiers.Select(i => (BsonValue)i); clauses.Add(MonQ.Query.In(Field.PRIMARYKEY, ids)); IMongoQuery query = MonQ.Query.And(clauses); MongoCursor <BsonDocument> cursor = collection.Find(query); if (sortby != null) { cursor = cursor.SetSortOrder(MonQ.SortBy.Ascending(sortby)); } else { cursor = cursor.SetSortOrder(MonQ.SortBy.Descending(Field.WHEN)); } return(cursor.ToEntries().ToList()); }
//public Interaction Get(string primarykey) //{ // IMongoQuery query = MonQ.Query.EQ(Field.PRIMARYKEY, primarykey); // BsonDocument document = collection.FindOne(query); // if (document != null) // { // Interaction entry = document.ToInteraction(); // return entry; // } // else // { // return null; // } //} public IList <Entry> GetCurrent(IEnumerable <string> identifiers, string sortby = null) { var clauses = new List <IMongoQuery>(); IEnumerable <BsonValue> ids = identifiers.Select(i => (BsonValue)i); clauses.Add(MongoDB.Driver.Builders.Query.In(Field.REFERENCE, ids)); clauses.Add(MongoDB.Driver.Builders.Query.EQ(Field.STATE, Value.CURRENT)); IMongoQuery query = MongoDB.Driver.Builders.Query.And(clauses); MongoCursor <BsonDocument> cursor = collection.Find(query); if (sortby != null) { cursor = cursor.SetSortOrder(MongoDB.Driver.Builders.SortBy.Ascending(sortby)); } else { cursor = cursor.SetSortOrder(MongoDB.Driver.Builders.SortBy.Descending(Field.WHEN)); } return(cursor.ToEntries().ToList()); }