10gen-csharp-driver

C# 10gen and mongo: deserialization for members as interfaces

你说的曾经没有我的故事 提交于 2019-12-12 04:47:23
问题 All Consider this example: private class CollectionHolder { public ObjectId Id { get; set; } public MyCollection Collection { get; set; } } private class MyCollection : List<int> { public MyCollection(List<int> a) { this.AddRange(a); } } private static void CollectionTest() { var collection = database.GetCollection<MyCollection>("collectionTest"); collection.RemoveAll(); collection.Save(new CollectionHolder { Collection = new MyCollection(new List<int> { 1, 2, 3, 4, 5 }) }); var x =

How do you increment a field in mongodb using c#

眉间皱痕 提交于 2019-11-30 20:46:39
Thought this would be pretty straight forward, but my value is remaining the same (0). What I'd like to do is increment my UnreadMessages field when the user receives a message they haven't read and then decrement it when they have. So I thought code like this would work: var userHelper = new MongoHelper<User>(); //increment userHelper.Collection.Update(Query.EQ("Id", userId.ToId()), Update.Inc("UnreadMessages", 1)); //decrement userHelper.Collection.Update(Query.EQ("Id", userId.ToId()), Update.Inc("UnreadMessages", -1)); After running these no errors are thrown but the value doesn't change

How do you increment a field in mongodb using c#

爷,独闯天下 提交于 2019-11-30 04:49:47
问题 Thought this would be pretty straight forward, but my value is remaining the same (0). What I'd like to do is increment my UnreadMessages field when the user receives a message they haven't read and then decrement it when they have. So I thought code like this would work: var userHelper = new MongoHelper<User>(); //increment userHelper.Collection.Update(Query.EQ("Id", userId.ToId()), Update.Inc("UnreadMessages", 1)); //decrement userHelper.Collection.Update(Query.EQ("Id", userId.ToId()),

How to query a sub document collection using MongoDB and C# driver

一曲冷凌霜 提交于 2019-11-28 08:20:57
问题 I have the following structure: public class ThreadDocument { public ThreadDocument() { Messages = new List<Message>(); Recipients = new List<Recipient>(); } [JsonIgnore] public ObjectId Id { get; set; } public IList<Recipient> Recipients { get; set; } public IList<Message> Messages { get; set; } public DateTime LastMessageSent { get; set; } public string LastSentByUserName { get; set; } public string LastSentAvatarUrl { get; set; } public string Snippet { get; set; } public int MessageCount