public void UpdateItem(TaskMessage item) { Dictionary <string, object> holder = item.GetHolder(); object id = holder["_id"]; if (id == null || !(id is ObjectId)) { throw new Exception("_id of queue element is missing"); } BsonObjectId objid = new BsonObjectId((ObjectId)id); holder.Remove("_id"); MongoMessage msg = new MongoMessage { ExtraElements = holder, id = objid }; //var result = Collection.Save(msg, new MongoInsertOptions() { WriteConcern = new WriteConcern() { Journal = true } }); var result = Collection.Save(msg); if (!result.Ok) { throw new Exception("error in update to mongo queue: " + result.ToJson()); } }
public TaskMessage GetItem() { CheckConnection(); var cursor = Collection.Find(QueryFeature).SetSortOrder(SortFeature); cursor.Limit = 1; MongoMessage mms = cursor.FirstOrDefault(); if (mms == null)//empty { return(null); } TaskMessage msg = new TaskMessage(mms.ExtraElements); msg.Holder.Add("_id", mms.id.Value); return(msg); }
public TaskMessage GetItemFifo() { CheckConnection(); TaskQueue.TQItemSelector selector = TaskQueue.TQItemSelector.DefaultFifoSelector; var cursor = Collection.Find(MongoSelector.GetQuery(selector)).SetSortOrder(); cursor.Limit = 1; MongoMessage mms = cursor.FirstOrDefault(); if (mms == null)//empty { return(null); } TaskMessage msg = new TaskMessage(mms.ExtraElements); msg.Holder.Add("_id", mms.id.Value); return(msg); }
public void UpdateItem(TaskMessage item) { Dictionary<string, object> holder = item.GetHolder(); object id = holder["__id"]; if (id == null || !(id is ObjectId)) throw new Exception("__id of queue element is missing"); BsonObjectId objid = new BsonObjectId((ObjectId)id); holder.Remove("__id"); MongoMessage msg = new MongoMessage { ExtraElements = holder, id = objid }; //var result = Collection.Save(msg, new MongoInsertOptions() { WriteConcern = new WriteConcern() { Journal = true } }); var result = Collection.Save(msg); if (!result.Ok) throw new Exception("error in update to mongo queue: " + result.ToJson()); }