mongodb.driver

How to fetch data from MongoDB collection in C# using Regular Expression?

穿精又带淫゛_ 提交于 2021-02-05 08:00:31
问题 I am using MongoDB.Drivers nuget package in my MVC (C#) web application to communication with MongoDB database. Now, I want to fetch data based on specific column and it's value. I used below code to fetch data. var findValue = "John"; var clientTest1 = new MongoClient("mongodb://localhost:XXXXX"); var dbTest1 = clientTest1.GetDatabase("Temp_DB"); var empCollection = dbTest1.GetCollection<Employee>("Employee"); var builder1 = Builders<Employee>.Filter; var filter1 = builder1.Empty; var

Projecting results from MongoDb Find in F#

人走茶凉 提交于 2021-01-28 21:50:56
问题 I'm trying to query MongoDB using MongoDB.Driver and return a partial result using mongo projection. I've figured out how to query without projection, but not a partial result. This is my function for finding results: let Find<'a> collectionName (filterDefinition: FilterDefinition<'a>) = let collection = database.GetCollection<'a> collectionName collection.Find(filterDefinition).ToEnumerable() |> List.ofSeq This is an example of how I call it: let findByIdFilter id = Builders<MyModel>.Filter

How to get connection status in the C# MongoDB driver v2.0?

混江龙づ霸主 提交于 2020-01-03 09:24:07
问题 We are starting using new MongoDB driver v2 and we can't understand whether we are connected to the db or not. Our repository code: var client = new MongoClient("mongodb://{wrong-host}:{wrong-port}/{dbbname}"); var database = client.GetDatabase(url.DatabaseName); Where wrong-host and wrong-port are invalid values. First we thought that exception will be raised if no one is listening on specified address but driver doesn't throws. Next step was to invoke method on the db: var dbs = client

MongoDb / C# filter and get all subdocuments

不羁岁月 提交于 2019-12-30 12:49:07
问题 I'm having difficulties querying a Mongo-DB collection. The document I'm using public class Customer { public ObjectId Id { get; set; } public int CustomerId { get; set; } public List<Address> Addresses { get; set; } } public class Address { public string Name { get; set; } } Some sample-Data { CustomerId: 2, Addresses: [ { Name: "Daniel" }, { Name: "Eric" }, { Name: "Dan" } ] } I now want to query the documents by the CustomerId and filter some of the Addresses-values to return all Addresses

How to make comlex query MongoDB with Powershell

爷,独闯天下 提交于 2019-12-21 05:36:23
问题 I need to retrieve data from mongoDB using Powershell. Let's say I have db.orders collection and need to retrieve only orders created during last week and retrieve only specific columns for instance _id, status, createdAt fields. Orders collection schema { "_id": ObjectId("56cf9bab78e9fd46ec557d69"), "status" : "ordered", ... "total": 343, "createdAt": ISODate("2016-01-15T17:29:09.342Z") } I can query it in mongo shell like this db.orders.find({ "createdAt" : { $lt: new Date(), $gte: new Date

How to make comlex query MongoDB with Powershell

≡放荡痞女 提交于 2019-12-03 21:02:51
I need to retrieve data from mongoDB using Powershell. Let's say I have db.orders collection and need to retrieve only orders created during last week and retrieve only specific columns for instance _id, status, createdAt fields. Orders collection schema { "_id": ObjectId("56cf9bab78e9fd46ec557d69"), "status" : "ordered", ... "total": 343, "createdAt": ISODate("2016-01-15T17:29:09.342Z") } I can query it in mongo shell like this db.orders.find({ "createdAt" : { $lt: new Date(), $gte: new Date(new Date().setDate(new Date().getDate()-7)) } }, {_id: 1, status: 1, createdAt: 1 }) But I need to do