Exemple #1
0
        /// <summary>
        /// 基于Linq的查询
        /// </summary>
        /// <param name="filter">过滤器</param>
        /// <returns></returns>
        public List <Dictionary <string, object> > Find(string dbName, string tableName, string jsonString, int pageIndex = 0, int pageSize = int.MaxValue, object exParam = null)
        {
            if (null != this.mongo)
            {
                var res = mongo.Find(dbName, tableName, jsonString, pageIndex, pageSize);
                return(res);
            }
            else if (null != this.sqlserver)
            {
                var res = this.sqlserver.Find(jsonString, exParam as List <KeyValuePair <string, object> >);
                return(res);
            }

            return(null);
        }
Exemple #2
0
        /// <summary>
        /// 移动数据
        /// </summary>
        /// <param name="sourceKeyName"></param>
        /// <param name="sourceDbName"></param>
        /// <param name="sourceCollectionName"></param>
        /// <param name="sourceFilter"></param>
        /// <param name="targetKeyName"></param>
        /// <param name="targetDbName"></param>
        /// <param name="targetCollectionName"></param>
        /// <param name="needDeleteSource"></param>
        public static void MoveCollection(MongoDB sourceInst, string sourceDbName, string sourceCollectionName, string sourceFilter, MongoDB targetInst, string targetDbName, string targetCollectionName, bool needDeleteSource = false)
        {
            if (null != sourceInst && null != targetInst)
            {
                sourceInst.EventTraverse += (object sender, EventArgs e) =>
                {
                    var ee     = e as EventProcEventArgs;
                    var dict   = ee.Default as Dictionary <string, object>;
                    var filter = string.Format("{{\"_id\":ObjectId('{0}')}}", dict["_id"]);
                    targetInst.Save3(targetDbName, targetCollectionName, dict, filter);

                    LOGGER.Log(string.Format("正在转移数据 {0}", dict["_id"]));
                    ;                   if (true == needDeleteSource)
                    {
                        sourceInst.Delete(sourceDbName, sourceCollectionName, filter);
                    }
                };

                sourceInst.Find(sourceDbName, sourceCollectionName, sourceFilter);
            }
        }