mongodb-.net-driver

How can you debug stored javascript functions in MongoDB?

 ̄綄美尐妖づ 提交于 2019-12-01 16:57:54
问题 I'm thinking of moving some workflow logic from C# code to stored JS in MongoDB (for example, wen a user sends a message, a bunch or records is to be created in different collections, which right now I do in C#), but I'm concerned whether I would be able to debug that JS code if things don't work correctly. 回答1: There isn't a particular facility for that. One thing you could do is run some of that code in the mongo shell, which can execute exactly the same javascript as the server. The shell

How to create a new database in MongoDB using the c# driver

家住魔仙堡 提交于 2019-12-01 16:55:50
I have read through the mongodb documentation and cannot seem to find out how to create a new database. For example, in the documentation it says I can access the "test" database like this: db.test.find() Now what if I want to create my own database using syntax like this: db.MyDB.find() Also, is there any documentation I can read online I can further read about creating databases and collections using the DOS interface and the c# driver? I may be wrong, but buried in this documentation it looks like the call to GetDatabase on the server object will actually create the database if it has not

MongoDB C# Driver Serialization with dynamic objects

坚强是说给别人听的谎言 提交于 2019-12-01 16:51:40
I've got a model that looks like: public class Record { public Record() { Created = DateTime.Now; } public string Id { get; set; } public string ApplicationId { get; set; } public Dictionary<string, dynamic> Values { get; set; } public DateTime Created { get; set; } } that's stored in MongoDB using the MongoDB C# Driver. This works GREAT when I do things like: { applicationId: "52f52db8008a280f583c9ff6", values: { "52f9410a324e68055f39f8c0": 245234 "52f941096d82a531e700e56b": "sdfasdf" "52fa4a96e0b2e0d4e61d0a03": "52fa4a9b91c477e367ab99e6" } } but when I try to add an array of strings like: {

How to create Bson Document with Null value using C# official driver?

早过忘川 提交于 2019-12-01 16:29:40
I have objects with 3 string fields Country, Province, City. They can contain null or some string name. I wanna query all data with the exact same values. For Example i need all data where City = null, Province = "WA", Country = "USA" I created BsonDocument: var lookup = new QueryDocument { {"GeoPosition.City", userLocation.City}, {"GeoPosition.Province", userLocation.Province}, {"GeoPosition.Country", userLocation.Country} }; But null field was thrown away and document looks like: { "GeoPosition.Province" : "WA", "GeoPosition.Country" : "USA" } If i'm triing to use Query.EQ("GeoPosition.City"

MongoDb TTL on nested document is possible?

天涯浪子 提交于 2019-12-01 16:15:00
I want to know if it's possible to use TTL on nested documents. Scenario I have Account and inside I have Sessions . Sessions need to expire in 30 minutes. I've set everything up but obviously when I set TTL index on Account.Sessions.EndDateTime it removes the whole Account . Can I make sure it removes only Session ? This is what it looks like in database. Notice how it will delete whole Account and not only Session when EndDateTime will come. { "_id" : ObjectId("53af273888dba003f429540b"), "Email" : "steve@s3te5ve.com", "PasswordHash" : "CZaBEQRbwWNgJBjyhks7gH0Z3v5ZvDkW29pryF0DEXyE8rIw0NA4x39

MongoDB C# Driver Serialization with dynamic objects

佐手、 提交于 2019-12-01 15:47:26
问题 I've got a model that looks like: public class Record { public Record() { Created = DateTime.Now; } public string Id { get; set; } public string ApplicationId { get; set; } public Dictionary<string, dynamic> Values { get; set; } public DateTime Created { get; set; } } that's stored in MongoDB using the MongoDB C# Driver. This works GREAT when I do things like: { applicationId: "52f52db8008a280f583c9ff6", values: { "52f9410a324e68055f39f8c0": 245234 "52f941096d82a531e700e56b": "sdfasdf"

Mongo DB with C# - document added regardless of transaction

北战南征 提交于 2019-12-01 12:14:32
问题 I'm trying to test the newly supported transactions in Mongo DB with a simple example I wrote. I'm using Mongo DB version 4.0.5 with driver version 2.8.1. It's only a primary instance with no shards/replicas. I must be missing something basic in the following code. I create a Mongo client, session & database, then start a transaction, add a document and abort the transaction. After this code, I expect nothing to change in the database, but the document is added. When debugging I can also see

MongoDB select all where field value in a query list

青春壹個敷衍的年華 提交于 2019-12-01 11:31:06
How to achieve below SQL in MongoShell? Select TableA.* from TableA where TableA.FieldB in (select TableB.FieldValue from TableB) Mongo doc gives some example of db.inventory.find( { qty: { $in: [ 5, 15 ] } } ) I want that array be dynamically from another query. Is it possible? Extending my question I have a collection of bot names bots collection { "_id" : ObjectId("53266697c294991f57c36e42"), "name" : "teoma" } I have a collection of user traffic, in that traffic collection, I have a field useragent userTraffic Collection { "_id" : ObjectId("5325ee6efb91c0161cbe7b2c"), "hosttype" : "http",

Mongodb authentication [duplicate]

*爱你&永不变心* 提交于 2019-12-01 11:03:10
This question already has an answer here: MongoDB GridFs with C#, how to store files such as images? 3 answers How do I use authentication with mongodb via the official c# driver? I can't find any API methods to authenticate, other than internal members. Authentication credentials should be specified in your connection string, using the following connection string format: mongodb://[username:password@]hostname[:port][/[database][?options]] See full details here in the MongoDB C# Driver Tutorial 来源: https://stackoverflow.com/questions/10101506/mongodb-authentication

MongoDB select all where field value in a query list

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 09:34:36
问题 How to achieve below SQL in MongoShell? Select TableA.* from TableA where TableA.FieldB in (select TableB.FieldValue from TableB) Mongo doc gives some example of db.inventory.find( { qty: { $in: [ 5, 15 ] } } ) I want that array be dynamically from another query. Is it possible? Extending my question I have a collection of bot names bots collection { "_id" : ObjectId("53266697c294991f57c36e42"), "name" : "teoma" } I have a collection of user traffic, in that traffic collection, I have a field