Код: Выделить всё
{
"_id": {
"$oid": "6***********************8"
},
"Username": "J",
"Password": "k"
}
Код: Выделить всё
using System.Collections.Generic;
using Microsoft.UI.Xaml;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
namespace LearnMongoDBTest
{
///
/// An empty window that can be used on its own or navigated to within a Frame.
///
public sealed partial class MainWindow : Window
{
private List templates;
public MainWindow()
{
this.InitializeComponent();
LoadDB();
}
public async void LoadDB()
{
var mongoClient = new MongoClient("");
var database = mongoClient.GetDatabase("CPSUSERS");
var collection = database.GetCollection("CPSCollection");
templates = await collection.Find(new BsonDocument()).Limit(10).ToListAsync();
LoadLists();
}
public void LoadLists()
{
foreach (var entry in templates)
{
myListBox.Items.Add(entry.Username);
myListBox2.Items.Add(entry.Password);
}
}
}
public class Template
{
[BsonId]
public ObjectId Id { get; set; }
[BsonElement("Username")]
public string Username { get; set; }
[BsonElement("Password")]
public string Password { get; set; }
}
}
Код: Выделить всё
Exception thrown: 'MongoDB.Driver.MongoConnectionException' in MongoDB.Driver.dll,
Exception thrown: 'System.MissingMethodException' in MongoDB.Bson.dll,
Exception thrown: 'System.MissingMethodException' in MongoDB.Driver.dllПодробнее здесь: https://stackoverflow.com/questions/793 ... de-c-sharp
Мобильная версия