Simple use of mongdb. Net tool library mongorepository.
Recently, I studied mongodb database and used a class library, Mongo warehouse, which is open source in. Net environment. Some simple operations of data are very easy to use, especially for later reference.
The specific use process is as follows:
1、 Create a new project and get the library on nuget.
2、 Set database address in configuration file
3、 Create a new data entity, inherit the entity, and define the required fields
4、 Pay attention to the use of several common field properties
[bsonelement (“Rename”)] is used to rename the name of a field in the database.
[bsonignore] this property is used to ignore fields and not generate them in the database.
[bsonignoreifnull] this property is generally used on collection objects. When the collection is empty, fields are ignored and are not generated in the database.
The [collectionname (“collectionname”)] secondary property is used to name the table name. The table name of the database 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 entity object
2. Add data by entity
3. Update data according to ID
4. Delete data according to specified conditions,
5. Get data, get data can be obtained according to conditions, or get all data, and return multiple forms.
So far, the basic data addition, deletion, modification and query are completed. GitHub address: https://github.com/robthree/mongorepository
We hope that colleagues can correct the shortcomings.
The above is the whole content of this article. I hope it will help you in your study, and I hope you can support developepaer more.