public BuddyItem[] GetAllBuddy(string username)
        {
            var db = GetDatabase();

            if (!db.CollectionExists("friends"))
            {
                return(new BuddyItem[0]);
            }
            var           collection = db.GetCollection("friends");
            QueryDocument queryDoc   = new QueryDocument();

            queryDoc.Add("owner", username.ToLower());
            var results = collection.Find(queryDoc);

            BuddyItem[] items = new BuddyItem[results.Size()];
            int         i     = 0;

            foreach (var item in results)
            {
                BuddyItem newItem = new BuddyItem();
                newItem.Username  = item.GetElement("username").Value.AsString;
                newItem.GroupName = item.GetElement("group").Value.AsString;
                if (item.Contains("remark"))
                {
                    newItem.Remark = item.GetElement("remark").Value.AsString;
                }
                if (item.Contains("nickname"))
                {
                    newItem.Nickname = item.GetElement("nickname").Value.AsString;
                }
                items[i++] = newItem;
            }
            return(items);
        }
        public BuddyItem GetBuddy(string owner, string friend)
        {
            var db = GetDatabase();

            if (!db.CollectionExists("friends"))
            {
                return(null);
            }
            var           collection = db.GetCollection("friends");
            QueryDocument queryDoc   = new QueryDocument();

            queryDoc.Add("owner", owner.ToLower());
            queryDoc.Add("username", friend.ToLower());
            var results = collection.Find(queryDoc);

            results.Limit = 1;

            foreach (var item in results)
            {
                BuddyItem newItem = new BuddyItem();
                newItem.Username  = item.GetElement("username").Value.AsString;
                newItem.GroupName = item.GetElement("group").Value.AsString;
                if (item.Contains("remark"))
                {
                    newItem.Remark = item.GetElement("remark").Value.AsString;
                }
                if (item.Contains("nickname"))
                {
                    newItem.Nickname = item.GetElement("nickname").Value.AsString;
                }

                return(newItem);
            }
            return(null);
        }
        public BuddyItem GetBuddy(string owner, string friend)
        {
            var db = GetDatabase();
            if (!db.CollectionExists("friends"))
                return null;
            var collection = db.GetCollection("friends");
            QueryDocument queryDoc = new QueryDocument();
            queryDoc.Add("owner", owner.ToLower());
            queryDoc.Add("username", friend.ToLower());
            var results = collection.Find(queryDoc);
            results.Limit = 1;

            foreach (var item in results)
            {
                BuddyItem newItem = new BuddyItem();
                newItem.Username = item.GetElement("username").Value.AsString;
                newItem.GroupName = item.GetElement("group").Value.AsString;
                if (item.Contains("remark"))
                    newItem.Remark = item.GetElement("remark").Value.AsString;
                if (item.Contains("nickname"))
                    newItem.Nickname = item.GetElement("nickname").Value.AsString;

                return newItem;

            }
            return null;
        }
        public BuddyItem[] GetAllBuddy(string username)
        {
            var db = GetDatabase();
            if (!db.CollectionExists("friends"))
                return new BuddyItem[0];
            var collection = db.GetCollection("friends");
            QueryDocument queryDoc = new QueryDocument();
            queryDoc.Add("owner", username.ToLower());
            var results = collection.Find(queryDoc);
            BuddyItem[] items = new BuddyItem[results.Size()];
            int i = 0;
            foreach (var item in results)
            {
                BuddyItem newItem = new BuddyItem();
                newItem.Username = item.GetElement("username").Value.AsString;
                newItem.GroupName = item.GetElement("group").Value.AsString;
                if (item.Contains("remark"))
                    newItem.Remark = item.GetElement("remark").Value.AsString;
                if (item.Contains("nickname"))
                    newItem.Nickname = item.GetElement("nickname").Value.AsString;
                items[i++] = newItem;

            }
            return items;
        }