MongoRepository, MongDB. Net tool library,

Source: Internet
Author: User

MongoRepository, MongDB. Net tool library,

Simple use of MongoRepository

 

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

I also hope you can correct the shortcomings.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.