Reputation: 182
I'm making an authentication system for my C# program, I want the program to:
key
with a specific string valueExample of my objects in the collection:
_id: "XXX"
hwid: "the key/value pair that I want to filter for"
details: {
discord_id: int
discord_name: "string"
ip_address: "string"
serial: "XXX (same as _id name)"
}
So what I want to achieve is is that my program checks if my string (HardwareID.Output()
) is in any of the collection's hwid
keys.
The code I have so far:
public static void Connect()
{
var client = new MongoClient("connection works");
var database = client.GetDatabase("monza");
var collection = database.GetCollection<dynamic>("whitelist");
var filter = Builders<BsonDocument>.Filter.Eq("hwid", HardwareID.Output()); // grabs string from another class
var dataObjects = collection.Find(filter).ToList();
}
However I get the this error when trying this:
CS1503: Argument 2: cannot convert from 'MongoDB.Driver.FilterDefinition<MongoDB.Bson.BsonDocument>' to 'System.Linq.Expressions.Expression<System.Func<dynamic, bool>>'
Regardless of the error I don't think this is all I need to achieve my goal and I can't find any information on how to do this iN C#.
Upvotes: 0
Views: 61
Reputation: 667
I do not know why you're using dynamic. Try this:
public static void Connect()
{
var client = new MongoClient("mongodb://127.0.0.1:27017");
var database = client.GetDatabase("monza");
var collection = database.GetCollection<BsonDocument>("whitelist");
var filter = Builders<BsonDocument>.Filter.Eq("hwid", HardwareID.Output()); // grabs string from another class
var dataObjects = collection.Find(filter).ToList();
}
Upvotes: 2