I just started with MongoDB. I am using it with C# drivers. Currently C# class looks like this:
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public string userId { get; set; }
public List<string> filters { get; set; }
With this class I am able to save and fetch the records in MongoDB.
What I want :- Instead of creating a separate property to hold ID
(in my case its Id
property), I want to make userId
property as the ObjectId.
Please note , I will be supplying the userId which will be a unique string value
. Is it possible to achieve this with MongoDB?
Sure it is possible.
just put [BsonId] on userId prop and delete Id property
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.