Exemple #1
0
        protected virtual int DoUpdate(Connector.Database db, Doc row, IDataStoreKey key, FieldFilterFunc filter = null)
        {
            var doc = convertDocToBSONDocumentWith_ID(row, "update", filter);
            var _id = doc[Connector.Protocol._ID];

            doc.Delete(Connector.Protocol._ID);
            if (doc.Count == 0)
            {
                return(0);              // nothing to update
            }
            //20160212 spol
            if (filter != null)
            {
                var wrapDoc = new BSONDocument();
                wrapDoc.Set(new BSONDocumentElement(Connector.Protocol.SET, doc));
                doc = wrapDoc;
            }

            var tname = GetCollectionName(row.Schema);

            var collection = db[tname];

            var qry = new Connector.Query();

            qry.Set(_id);
            var upd = new Connector.UpdateEntry(qry, doc, false, false);

            var result = collection.Update(upd);

            CheckCRUDResult(result, row.Schema.Name, "update");

            return(result.TotalDocumentsAffected);
        }
        public Connector.Query MakeQuery(Connector.Database db, Query query, QuerySource source, out Connector.Collection collection)
        {
            if (source.ModifyTarget.IsNullOrWhiteSpace())
            {
                throw new MongoDbDataAccessException(StringConsts.QUERY_MODIFY_TARGET_MISSING_ERROR + "\n" + Source.OriginalSource);
            }

            collection = db[source.ModifyTarget];

            return(MakeQuery(query, source));
        }
Exemple #3
0
        protected virtual int DoUpsert(Connector.Database db, Doc row, FieldFilterFunc filter = null)
        {
            var doc = convertDocToBSONDocumentWith_ID(row, "upsert", filter);

            var tname = GetCollectionName(row.Schema);

            var collection = db[tname];

            var result = collection.Save(doc);

            CheckCRUDResult(result, row.Schema.Name, "upsert");

            return(result.TotalDocumentsAffected);
        }
Exemple #4
0
        protected virtual int DoDelete(Connector.Database db, Doc row, IDataStoreKey key)
        {
            var doc = convertDocToBSONDocumentWith_ID(row, "delete");

            var tname = GetCollectionName(row.Schema);

            var collection = db[tname];

            var qry = new Connector.Query();

            qry.Set(doc[Connector.Protocol._ID]);

            var result = collection.Delete(new Connector.DeleteEntry(qry, Connector.DeleteLimit.OnlyFirstMatch));

            CheckCRUDResult(result, row.Schema.Name, "delete");

            return(result.TotalDocumentsAffected);
        }