Ejemplo n.º 1
0
		public static Document Parse(string text)
		{
			var dp = new DocumentParser();
			var doc = dp.Parse(text) as Document;
			if(text.Trim().Length > 0 && doc == null)
				throw new Exception("Document unparsable '" + text + "'");
			return doc;
		}
Ejemplo n.º 2
0
		public static List<object> ParseArray(string array)
		{
			var dp = new DocumentParser();
			var arr = dp.Parse(array) as List<object>;
			if(array.Trim().Length > 0 && arr == null)
				throw new Exception("Array unparsable '" + array + "'");
			return arr;
		}
Ejemplo n.º 3
0
Archivo: MDB.cs Proyecto: okku/Mongdio
        public static Document CreateIndexes(string dbName, string collectionNamespace, string pattern)
        {
            using(var db = GetMongo())
            {
                var dp = new DocumentParser();
                var d = dp.Parse(pattern) as Document;
                if(d == null)
                    throw new ArgumentException("Illegal pattern");

                var name = d.ToLine();
                var cmd = new Document().Append("name",name).Append("ns", collectionNamespace).Append("key",d);
                db[dbName]["system.indexes"].Insert(cmd);

                cmd = new Document().Append("name", name);
                return db[dbName]["system.indexes"].FindOne(cmd);
            }
        }
Ejemplo n.º 4
0
        public static Document CreateIndexes(string dbName, string collectionNamespace, string pattern)
        {
            using (var db = GetMongo())
            {
                var dp = new DocumentParser();
                var d  = dp.Parse(pattern) as Document;
                if (d == null)
                {
                    throw new ArgumentException("Illegal pattern");
                }

                var name = d.ToLine();
                var cmd  = new Document().Append("name", name).Append("ns", collectionNamespace).Append("key", d);
                db[dbName]["system.indexes"].Insert(cmd);

                cmd = new Document().Append("name", name);
                return(db[dbName]["system.indexes"].FindOne(cmd));
            }
        }
Ejemplo n.º 5
0
        public string DeleteObject(string text)
        {
            var dp = new DocumentParser();
            var d = dp.Parse(text) as Document;
            if(d == null)
                return "No object";
            if(_lastCollectionUsed == null)
                return "No collection";

            using(var db = MDB.GetMongo())
            {
                if(d.Contains("_id") && d["_id"] != null)
                {
                    var selector = new Document();
                    selector["_id"] = d["_id"];
                    db[DataBaseName][_lastCollectionUsed].Delete(selector);
                    return string.Format("Object with _id: {1} deleted in collection '{0}'", _lastCollectionUsed, d["_id"]);
                }
                return string.Format("Object contains no id");
            }
        }
Ejemplo n.º 6
0
 public bool TryParseTextAsDocument(string text, out bool containsId)
 {
     containsId = false;
     var dp = new DocumentParser();
     var d = dp.Parse(text) as Document;
     if(d != null)
         containsId = d.Contains("_id");
     return d != null;
 }
Ejemplo n.º 7
0
        public string SaveObject(string text)
        {
            var dp = new DocumentParser();
            var d = dp.Parse(text) as Document;
            if(d == null)
                return "No object";
            if(_lastCollectionUsed == null)
                return "No collection";

            using(var db = MDB.GetMongo())
            {
                UpdateObjectAlwaysUpsert(_lastCollectionUsed,d,db);
                return string.Format("Object saved in collection '{0}'", _lastCollectionUsed);
            }
        }