MONGO data type conversions in "MongoDB" C #

Source: Internet
Author: User

People who have used MONGO know that MONGO use Bson type, there are string,int,date,bool and other data types, specifically not detailed.

There is a problem when using MONGO's C # official driver to match the data types in Bson with the data types in C #.

Here are the types of data that I encounter in the actual project that need to be matched.

Id

For example, all MONGO documents have a _id, if not identified, directly in the object class to define a _id attribute, then the data read or save the error.

Therefore, the object class should be defined as follows:

[Bsonid]  Public Get set; }

Datetime

Another example is to define a datetime type in the object class, save it to MONGO and then read it and find out that the date is smaller than the date deposited.

The original MONGO database will save time to UCT time, that is, GMT, 8 hours later than Beijing time.

However, if you precede the time attribute with the following label, you can resolve the issue.

[Bsondatetimeoptions (Kind = datetimekind.local)]  Public Get set; }

MONGO data type conversions in "MongoDB" C #

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.