MongoRepository, MongDB. Net tool library,
MongoRepository, MongDB. Net tool Library, is simple to use.
I recently studied the MongoDB database and used an open-source Mongo library in the. net environment. Some simple operations on data are very easy to use, and special records are provided for later reference.
The procedure is as follows:
1. Create a project and obtain the library on Nuget.
2. Set the database address in the configuration file
3. Create a data Entity, inherit the Entity, and define the required fields
4. Pay attention to the use of common field attributes
[BsonElement ("reName")] is used to reName fields in the database.
[BsonIgnore] This attribute is used to ignore fields that are not generated in the database.
[BsonIgnoreifNull] This attribute is generally used on a collection object. When the set is empty, fields are ignored and not generated in the database.
[CollectionName ("collectionName")] This attribute is used to name a table. The database table name is not the entity name, but the name here.
[BsonKnowTypes (typeof (class)] This attribute is used to define known types.
5. Data Interaction
1. Instance Object
2. Add Data Based on entities
Or:
3. Update data by id
4. delete data based on specified conditions,
5. obtain data. You can obtain the data based on conditions or all the data and return multiple forms.
So far, the basic data addition, deletion, modification and query is completed, GitHub address: https://github.com/RobThree/MongoRepository
We also hope that our peers can correct the shortcomings.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.