using MongoDB.Bson; using MongoDB.Driver; using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace AIAHTML5.API.Models { public class PixelLocator { internal static dynamic GetBodyRegionsPixelData(string layerNumber, string bodyViewIndex, string systemNumber, string zoom) { try { //var client = new MongoClient("mongodb://192.168.90.43:27017"); var client = new MongoClient(); var db = client.GetDatabase("AIAHTML5"); var col = db.GetCollection("DAImages"); var pipeline = new BsonDocument[] { new BsonDocument{{"$unwind", "$terms"}}, new BsonDocument{ { "$match", new BsonDocument("terms.SystemNumbers", Convert.ToInt32(systemNumber)).Add("bodyViewIndex", Convert.ToInt32(bodyViewIndex)).Add("layerNumber", Convert.ToInt32(layerNumber)).Add("zoom", Convert.ToInt32(zoom)) }}, new BsonDocument { {"$project", new BsonDocument() .Add("_id", 0) .Add("terms", 1) .Add("bodyRegionId", 1) } } }; var pixelData = col.Aggregate(pipeline).ToList(); return pixelData.ToJson(); } catch (Exception e) { //string error = e.Message + "..STACKTRACE: " + e.StackTrace; string error = "InternalServerError"; return error; } } } }