/// <summary> /// /// </summary> /// <param name="_objectIdentifier"></param> /// <returns></returns> public T Get(Guid _objectIdentifier) { BsonBinaryData id = new BsonBinaryData(_objectIdentifier.ToByteArray()); BsonDocument doc = MongoCollection.FindOneById(id); return(BsonHelper.Get <T>(doc)); }
/// <summary> /// /// </summary> /// <typeparam name="U"></typeparam> /// <param name="_mongoQuery"></param> /// <returns></returns> public U GetOneItem <U>(IMongoQuery _mongoQuery) where U : AbstractTGObject, new() { BsonDocument doc = MongoCollection.FindOne(_mongoQuery); if (doc != null) { return(BsonHelper.Get <U>(doc)); } return(null); }
/// <summary> /// /// </summary> /// <param name="_cursor"></param> /// <returns></returns> public List <T> GetList(MongoCursor _cursor) { List <T> items = new List <T>(); foreach (BsonDocument doc in _cursor) { items.Add(BsonHelper.Get <T>(doc)); } return(items); }
/// <summary> /// /// </summary> /// <typeparam name="U"></typeparam> /// <param name="_mongoCursor"></param> /// <returns></returns> public U GetOneItem <U>(MongoCursor _mongoCursor) where U : AbstractTGObject, new() { MongoCursor cursor = _mongoCursor.SetLimit(1); foreach (BsonDocument doc in cursor) { U obj = BsonHelper.Get <U>(doc); return(obj); } return(null); }
public List <T> GetByQuery(Guid _objectParentIdentifier) { List <T> objRet = new List <T>(); var query = new QueryDocument { { "ParentGuid", _objectParentIdentifier.ToString() } }; foreach (BsonDocument doc in MongoCollection.Find(query)) { objRet.Add(BsonHelper.Get <T>(doc)); } return(objRet); }
/// <summary> /// Does not modify the version guid. /// </summary> /// <param name="_obj"></param> public void PersistFromPropagation(T _obj) { if (HasParent && _obj.ParentGuid == null) { throw new Exception("Parent Guid not specified."); } _obj.PersistedDateTime = DateTime.UtcNow; BsonDocument document = BsonHelper.Get(_obj); MongoCollection.Save(document); PostPersist(_obj); }
public List <T> GetByQuery( Guid _objectParentIdentifier, string[] _objectVersionIdentifiers) { List <T> objRet = new List <T>(); foreach (string objectVersionIdentifier in _objectVersionIdentifiers) { var query = new QueryDocument { { "ParentGuid", _objectParentIdentifier.ToString() }, { "VersionGuid", objectVersionIdentifier } }; foreach (BsonDocument doc in MongoCollection.Find(query)) { objRet.Add(BsonHelper.Get <T>(doc)); } } return(objRet); }
/// <summary> /// Unconfirmed persist of data. Should only be used on low value data. /// </summary> /// <param name="_obj"></param> public void LazyPersist(T _obj) { BsonDocument document = BsonHelper.Get(_obj); MongoCollection.Save(document, WriteConcern.Unacknowledged); }