简体   繁体   中英

MongoDB Collection as Dictionary

I'm looking at having a mongodb collection.

As I understand it, a collection is just a group of objects.

I'm curious if it's possible to store a collection as a single object with multiple keys (as a dictionary).

Or if I can store multiple objects with a key value pair and somehow parse it into a Dictionary in c#.

I think I've figured out what I need.

I can store each object as a key value pair and then parse it within the c# like this:

    private readonly IMongoCollection<KeyValuePair<string, Object>> _logs;

    public Dictionary<string, Object> Get() => _logs.Find(pair => true).ToList().ToDictionary(x => x.Key, x=> x.Value);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM