Example #1
0
        public async Task Add(Channel channel)
        {
            IMongoCollection <Channel>     collection = _discordRepository.GetChannelCollection();
            IFindFluent <Channel, Channel> entry      = _discordRepository.GetChannelEntry(collection, channel);

            if (!entry.Any())
            {
                try
                {
                    await collection.InsertOneAsync(channel);
                }
                catch (Exception e)
                {
                    throw new MongoStoreException($"fatal error happened when adding channel data to mongodb", e);
                }
            }
        }
Example #2
0
        bool IQuery <T> .Exist()
        {
            IFindFluent <T, T> finder = null;
            var collection            = _db.GetCollection <T>(typeof(T).Name);

            if (whereExp != null)
            {
                finder = collection.Find <T>(whereExp);
            }
            else
            {
                FilterDefinition <T> filter = FilterDefinition <T> .Empty;
                finder = collection.Find <T>(filter);
            }

            return(finder.Any());
        }
Example #3
0
        /// <summary>
        /// 判断是否存在符合条件的数据
        /// </summary>
        /// <param name="collName">表名</param>
        /// <param name="filter">条件</param>
        /// <returns></returns>
        public bool Any(String collName, FilterDefinition <BsonDocument> filter)
        {
            IFindFluent <BsonDocument, BsonDocument> find = Database.GetCollection <BsonDocument>(collName).Find(filter);

            return(find.Any());
        }
Example #4
0
        /// <summary>
        /// 判断是否存在符合条件的数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collName">表名</param>
        /// <param name="filter">条件</param>
        /// <returns></returns>
        public bool Any <T>(String collName, FilterDefinition <T> filter)
        {
            IFindFluent <T, T> find = Database.GetCollection <T>(collName).Find(filter);

            return(find.Any());
        }