/// <summary> /// Demo deleting documents from collection. /// </summary> /// <param name="orders">The orders.</param> private static void DeleteAllDocumentsFromCollection(IMongoCollection orders) { Console.WriteLine("\n\n======= Delete Test ======="); Console.WriteLine(string.Format("Document Count Before Delete: [ {0} ]", orders.Count())); // Delete documents matching a criteria. orders.Delete(new Document { { "customerName", "Elmer Fudd" } }); Console.WriteLine(string.Format("Document Count After Deleting Elmer Fudd: [ {0} ]", orders.Count())); // Delete all docs. orders.Delete(new Document()); Console.WriteLine("Deleted all docs"); Console.WriteLine(string.Format("Document Count After Deleting All Docs: [ {0} ]\n", orders.Count())); }
/// <summary> /// Inserts a new document. /// </summary> /// <param name="orders">The orders.</param> private static void CreateAndInsertSingleDocumentIntoCollection( IMongoCollection orders ) { Console.WriteLine( "\n\n======= Insert Multiple Documents =======" ); Console.WriteLine( string.Format( "Document Count Before Insert: [ {0} ]", orders.Count() ) ); // Create a new order. var order = new Document(); order["OrderAmount"] = 57.22; order["CustomerName"] = "Elmer Fudd"; // Add the new order to the mongo orders colleciton. orders.Insert( order ); Console.WriteLine( string.Format( "Inserted: {0}", order ) ); Console.WriteLine( string.Format( "Document Count After Insert: [ {0} ]", orders.Count() ) ); }
protected override void Execute(IMongoCollection<BsonDocument> collection, bool async) { if (async) { collection.CountAsync(_filter, _options).GetAwaiter().GetResult(); } else { collection.Count(_filter, _options); } }
/// <summary> /// Demo inserting multiple document into collection. /// </summary> /// <param name="orders">The orders.</param> private static void CreateAndInsertMultipleDocumentIntoCollection( IMongoCollection orders ) { Console.WriteLine( "\n\n======= Insert Multiple Documents =======" ); Console.WriteLine( string.Format( "Document Count Before Insert: [ {0} ]", orders.Count() ) ); // Create new orders. var order1 = new Document(); order1["OrderAmount"] = 100.23; order1["CustomerName"] = "Bugs Bunny"; var order2 = new Document(); order2["OrderAmount"] = 0.01; order2["CustomerName"] = "Daffy Duck"; IEnumerable< Document > orderList = new List< Document > {order1, order2}; // Insert an IEnumerable. orders.Insert( orderList ); Console.WriteLine( string.Format( "Inserted: {0}", order1 ) ); Console.WriteLine( string.Format( "Inserted: {0}", order2 ) ); Console.WriteLine( string.Format( "Document Count After Insert: [ {0} ]", orders.Count() ) ); }
/// <summary> /// Adds all the new items into the empty database. /// </summary> /// <param name="itemsInDatabase">The items retrieved from the database.</param> /// <returns>The number of items in the database</returns> private long AddLoadedItemsToBlankDatabase(IMongoCollection <T> itemsInDatabase) { itemsInDatabase.InsertMany(LoadedItems); return(itemsInDatabase.Count(Filter)); }
protected long CountPostgresLines(IMongoCollection <BsonDocument> collection) { var query = MongoQueryHelper.LogLinesByFile(collection); return(collection.Count(query)); }
protected void uploadFileData(BsonDocument dirDoc, String subPath, IEnumerable <FileInfo> files) { string[] imageExtensions = { "png", "jpg", "jpeg", "gif" }; Regex regex = null; if (dirDoc.GetValue("codeRegex") != null) { regex = new Regex(dirDoc.GetValue("codeRegex").ToString()); } foreach (FileInfo file in files) { String content; String extension = file.Extension.Replace(".", "").ToLower(); if (imageExtensions.Contains(extension)) { byte[] imageArray = System.IO.File.ReadAllBytes(file.FullName); content = Convert.ToBase64String(imageArray); content = "data:image/" + extension + ";base64," + content; } else { StreamReader sr = new StreamReader(file.FullName, Encoding.UTF8); content = sr.ReadToEnd(); sr.Close(); } String code = ""; if (regex != null) { var v = regex.Match(file.Name); code = v.Groups[1].ToString(); } var query = new BsonDocument { { "source", _machineName }, { "path", dirDoc.GetValue("path").ToString() }, { "subpath", subPath }, { "fileName", file.Name } }; var doc = new BsonDocument { { "source", _machineName }, { "path", dirDoc.GetValue("path").ToString() }, { "subpath", subPath }, { "fileName", file.Name }, { "fileType", file.Extension }, { "code", code }, { "content", content }, { "length", content.Length }, { "processed", false }, { "dateCreated", file.LastWriteTime }, { "dateProcessed", "" } }; if (_syncFiles.Count(query) == 0) { _syncFiles.InsertOne(doc); } else { _syncFiles.ReplaceOne(query, doc); } } }
public override long Count(FilterDefinition <TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(_wrappedCollection.Count(CombineFilters(filter), options, cancellationToken)); }
public int Count(Expression <Func <TAggregate, bool> > filter) { var count = Collection.Count(filter); return((int)count); }
public long CountList(IMongoCollection <Long2shortViewModel> CollectionHandler) { return(CollectionHandler.Count(FilterDefinition <Long2shortViewModel> .Empty)); }
public long Count(FilterDefinition <T> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(collection.Count(filter, options, cancellationToken)); }
public long CountAll() { return(_dbSet.Count(_ => true)); //return _dbSet.AsQueryable<T>().Count(); }
public static void CreateDatabase(string connectionStr) { IMongoDatabase db = GetDatabaseFromConnectionString(connectionStr); IMongoCollection <Configuration> configs = db.GetCollection <Configuration>("configuration"); if (configs.Count(x => true) != 0) //Eğer collection boş ise db'yi boş sayıp indexleri yaratıyoruz. { return; } configs.Indexes.CreateOneAsync(Builders <Configuration> .IndexKeys.Ascending(nameof(Configuration.Name)).Ascending(nameof(Configuration.ApplicationName))); configs.Indexes.CreateOneAsync(Builders <Configuration> .IndexKeys.Ascending(nameof(Configuration.ApplicationName))); var setting1 = new Configuration { ApplicationName = "LiveTest", Name = "SupportedOs", Type = ConfigType.String, Value = "Windows | Linux", IsActive = true }; var setting2 = new Configuration { ApplicationName = "Live", Name = "SupportedOs", Type = ConfigType.String, Value = "Windows | Linux | Mac", IsActive = true }; var setting3 = new Configuration { ApplicationName = "LiveTest", Name = "ApiVersion", Type = ConfigType.Double, Value = "1.44", IsActive = true }; var setting4 = new Configuration { ApplicationName = "LiveTest", Name = "IsDebug", Type = ConfigType.Bool, Value = "True", IsActive = true }; var setting5 = new Configuration { ApplicationName = "LiveTest", Name = "Miliseconds", Type = ConfigType.Int, Value = "12345", IsActive = true }; configs.InsertOne(setting1); configs.InsertOne(setting2); configs.InsertOne(setting3); configs.InsertOne(setting4); configs.InsertOne(setting5); }
private bool CheckForAnyNote() { return(NotesCollection.Count(n => true) != 0); }
public long Count(FilterDefinition <T> filter) { var result = _collection.Count(filter); return(result); }
public void Add(Offer offer) { offer.Id = Convert.ToInt32(_offer.Count(new BsonDocument()) + 1); _offer.InsertOne(offer); }
public Task SaveAsync(TraceMetadata trace) { trace.Id = (int)_collection.Count(new BsonDocument(), null) + 1; return(_collection.InsertOneAsync(trace)); }
public static long GetCount() => _posts.Count(FilterDefinition <SimplePost> .Empty);
public override long Count(CancellationToken cancellationToken) { var options = CreateCountOptions(); return(_collection.Count(_filter, options, cancellationToken)); }
public void EnsureSeedData() { var context = new MongoDbContext(_connection); IMongoDatabase db = context.Database("mongocore"); IMongoCollection <UserDocument> userCollection = context.Collection <UserDocument>("mongocore", "usertasks"); var count = userCollection.Count(new BsonDocument()); if (count > 0) { Console.WriteLine($">>>>> {count} documents already exist in collection"); var filter = Builders <UserDocument> .Filter.Eq("Username", "sapaul"); var user = userCollection.Find(filter).First(); Console.WriteLine($"\n[Admin Info] {user.FirstName} {user.LastName}"); if (PasswordHasher.Match("sapaul", user.PasswordHash)) { Console.WriteLine("Password Match test #1 passed"); } if (!PasswordHasher.Match("sapauul", user.PasswordHash)) { Console.WriteLine("Password Match test #2 passed"); } return; } var task1 = new TaskDocument { Id = ObjectId.GenerateNewId(), Name = "Remember the milk!", Description = "", Done = true, }; var task2 = new TaskDocument { Id = ObjectId.GenerateNewId(), Name = "update bio", Description = "", Done = false }; userCollection.InsertOne(new UserDocument { Admin = true, FirstName = "Santanu", LastName = "Paul", Username = "******", Email = "*****@*****.**", PasswordHash = PasswordHasher.Generate("sapaul"), Tasks = new List <TaskDocument>(new[] { task1, task2 }) }); userCollection.InsertOne(new UserDocument { Admin = false, FirstName = "Joe", LastName = "Doe", Username = "******", Email = "*****@*****.**", PasswordHash = PasswordHasher.Generate("jodoe"), Tasks = new List <TaskDocument>(new[] { new TaskDocument { Id = ObjectId.GenerateNewId(), Name = "John's task 1", Done = false } }) }); userCollection.InsertOne(new UserDocument { Admin = false, FirstName = "Jane", LastName = "Doe", Username = "******", Email = "*****@*****.**", PasswordHash = PasswordHasher.Generate("jndoe"), Tasks = new List <TaskDocument>(new[] { new TaskDocument { Id = ObjectId.GenerateNewId(), Name = "Jane's task 1", Description = "some description", Done = false }, new TaskDocument { Id = ObjectId.GenerateNewId(), Name = "Jane's task 2", Description = "some more description", Done = true } }) }); count = userCollection.Count(new BsonDocument()); Console.WriteLine($">>>>> {count} documents created in collection"); }
/// <summary> /// Count the number of Vizportal requests in the collection. /// </summary> /// <param name="collection">The collection to search for requests in.</param> /// <returns>The number of Vizportal requests in the collection</returns> protected long CountVizportalRequests(IMongoCollection <BsonDocument> collection) { var query = MongoQueryHelper.VizportalRequestsByFile(collection); return(collection.Count(query)); }
public virtual bool Contains(Expression <Func <EntityModel, bool> > predicate) { return(DbSet.Count(predicate) > 0); }
public bool CheckForUser(string id) { return(_usersCollection.Count(n => n.Id == id) != 0); }
/// <summary> /// Counts the total entities in the repository. /// </summary> /// <returns>Count of entities in the collection.</returns> public virtual long Count() { return(collection.Count(Builders <T> .Filter.Empty)); }
public static long GetCount() { return(_images.Count(FilterDefinition <StoredImage> .Empty)); }
public virtual bool ContainsId(string id) { return(mongoCollection.Count(c => c.Id == id) > 0); }
public long countTotal() { return(_products.Count(product => true)); }
public long Count(FilterDefinition <T> filter) { return(_collection.Count(filter)); }
public override bool Exists(Identity id) => _meetingCollection.Count(x => x.Id == id.ToPersistenceIdentity()) == 1;
/// <summary> /// /// </summary> /// <param name="expression"></param> /// <returns></returns> public long Count(Expression <Func <T, bool> > expression) => _db.Count(expression);
/// <summary> /// Count the number of Search server events in the collection. /// </summary> /// <param name="collection">The collection to search for requests in.</param> /// <returns>The number of Searchserver Events in the collection</returns> protected long CountSearchserverEvents(IMongoCollection <BsonDocument> collection) { var query = MongoQuerySearchserverHelper.SearchserverByFile(collection); return(collection.Count(query)); }
public virtual long Count() { return(_collection.Count(new BsonDocument())); }
public static long Count <TDocument>(this IMongoCollection <TDocument> collection) { return(collection.Count(new BsonDocument())); }
public void Add(Product product) { product.Id = Convert.ToInt32(_products.Count(new BsonDocument()) + 1); _products.InsertOne(product); }