GetFunction() static private method

static private GetFunction ( IMongoFields fields ) : BsonDocument>.Func
fields IMongoFields
return BsonDocument>.Func
Exemplo n.º 1
0
        public IEnumerable <object> FindAs(Type documentType, IMongoQuery query, QueryFlags modes, IMongoSortBy sortBy, int skip, int first, IMongoFields fields)
        {
            var iter = QueryCompiler.Query(Documents, Documents2, query, sortBy, skip, first);

            if (fields == null)
            {
                return(iter.Select(x => BsonSerializer.Deserialize(x, documentType)));
            }

            var project = FieldCompiler.GetFunction(fields);

            return(iter.Select(project).Select(x => BsonSerializer.Deserialize(x, documentType)));
        }
Exemplo n.º 2
0
        public object FindAndModifyAs(Type documentType, IMongoQuery query, IMongoSortBy sortBy, IMongoUpdate update, IMongoFields fields, bool returnNew, bool upsert, out UpdateResult result)
        {
            foreach (var document in QueryCompiler.Query(Documents, Documents2, query, sortBy, 0, 0))
            {
                // if old is needed then deep(!) clone before update //_131103_185751
                BsonDocument output = null;
                if (!returnNew)
                {
                    output = document.DeepClone().AsBsonDocument;
                }

                UpdateDocument(document, UpdateCompiler.GetFunction((IConvertibleToBsonDocument)update, null, false));

                if (returnNew)
                {
                    output = document;
                }

                // project
                if (fields != null)
                {
                    var project = FieldCompiler.GetFunction(fields);
                    output = project(output);
                }

                // if old is needed then return it as already deep cloned
                result = new SimpleUpdateResult(1, true);
                if (!returnNew && documentType == typeof(Dictionary))
                {
                    return(new Dictionary(output));
                }
                else
                {
                    // deserialize to required type
                    return(BsonSerializer.Deserialize(output, documentType));
                }
            }

            // not found, insert
            if (upsert)
            {
                var document = InsertNewDocument(query, update);

                result = new SimpleUpdateResult(1, false);
                return(returnNew ? BsonSerializer.Deserialize(document, documentType) : null);
            }

            result = new SimpleUpdateResult(0, false);
            return(null);
        }