public IDocumentFindSortedCursor <TDocument, TProjection> SortByTextScore(Expression <Func <TProjection, object> > textScoreProperty) { _textScoreProperty = MongoHelpers.GetPropertyName(textScoreProperty); _sortDefinition = Builders <TDocument> .Sort.MetaTextScore(_textScoreProperty); return(this); }
public DocumentUpdateResult ReplaceOne(TDocument replacement, Expression <Func <TDocument, bool> > filter = null, bool insertIfNotExists = false) { var result = _collection.Value.ReplaceOne(_filterBuilder.CreateMongoFilter(filter), replacement, new UpdateOptions { IsUpsert = insertIfNotExists }); return(MongoHelpers.CreateReplaceResult(result, insertIfNotExists)); }
public DocumentUpdateResult UpdateMany(Action <IDocumentUpdateBuilder <TDocument> > update, Expression <Func <TDocument, bool> > filter = null, bool insertIfNotExists = false) { var result = _collection.Value.UpdateMany(_filterBuilder.CreateMongoFilter(filter), MongoDocumentUpdateBuilder <TDocument> .CreateMongoUpdate(update), new UpdateOptions { IsUpsert = insertIfNotExists }); return(MongoHelpers.CreateUpdateResult(result, insertIfNotExists)); }
public DocumentUpdateResult ReplaceOne(DynamicWrapper replacement, Func <IDocumentFilterBuilder, object> filter = null, bool insertIfNotExists = false) { var result = _collection.Value.ReplaceOne(_filterBuilder.CreateMongoFilter(filter), replacement, new UpdateOptions { IsUpsert = insertIfNotExists }); return(MongoHelpers.CreateReplaceResult(result, insertIfNotExists)); }
public DocumentUpdateResult UpdateMany(Action <IDocumentUpdateBuilder> update, Func <IDocumentFilterBuilder, object> filter = null, bool insertIfNotExists = false) { var result = _collection.Value.UpdateMany(_filterBuilder.CreateMongoFilter(filter), MongoDocumentUpdateBuilder <DynamicWrapper> .CreateMongoUpdate(update), new UpdateOptions { IsUpsert = insertIfNotExists }); return(MongoHelpers.CreateUpdateResult(result, insertIfNotExists)); }
public MongoDocumentStorageProvider(MongoConnection connection, string documentType = null) { if (string.IsNullOrEmpty(documentType)) { documentType = MongoHelpers.GetDefaultDocumentType <TDocument>(); } DocumentType = documentType; _database = new Lazy <IMongoDatabase>(connection.GetDatabase); _collection = new Lazy <IMongoCollection <TDocument> >(() => _database.Value.GetCollection <TDocument>(documentType)); _filterBuilder = new MongoDocumentFilterBuilder <TDocument>(); }
private IAsyncCursor <TProjection> CreateCursor() { var fluentCursor = _fluentCursor; if (!string.IsNullOrEmpty(_textScoreProperty)) { var projectionDefinition = fluentCursor.Options.Projection; var textScoreProjection = new BsonDocument(_textScoreProperty, new BsonDocument("$meta", "textScore")); var textScoreProjectionDefinition = new BsonDocumentProjectionDefinition <TDocument, TProjection>(textScoreProjection); fluentCursor.Options.Projection = (projectionDefinition != null) ? MongoHelpers.Combine(projectionDefinition, textScoreProjectionDefinition) : textScoreProjectionDefinition; } if (_sortDefinition != null) { fluentCursor = _fluentCursor.Sort(_sortDefinition); } return(fluentCursor.ToCursor()); }