MongoDB add, delete, modify
Introduction to MongoDB driver types 1. MongoDB official driver: mongo-csharp-driver, download address: https://github.com/mongodb/mongo-csharp-driver/downloads 2. Third-party driver samus , this is a frequently used driver with a relatively fast update frequency. In addition to supporting general operations, the samus driver also supports Linq Introduction to MongoDB driver types 1. MongoDB official driver: mongo-csharp-driver, download address: https://github.com/mongodb/mongo-csharp-driver/downloads 2. The third-party driver samus is a commonly used driver with a relatively fast update frequency. In addition to supporting general operations, the samus driver also supports Linq and Lambda expressions. Download address: https://github.com/samus/mongodb-csharp. The operation process of the two mongodb drivers on the mongodb database is basically the same, but there are differences in the implementation methods. For example, the samus driver not only supports general formal operations, but also supports Linq and Lambda expressions. Use MongoDB official driver to operate the database Unzip the package and get the following two files: MongoDB.Bson.dll: Serialization, Json related MongoDB.Driver.dll: mongodb driver Add references and introduce the above two DLLs into the project Introducing namespaces into code using MongoDB.Bson; using MongoDB.Driver; Obtain database connection service string cOnnectionString= ” mongodb://localhost ” ; //mongodb://[username:password@]hostname[:port][/[database][?options]] MongoServer server = MongoServer.Create(connectionString); // Connect to a MongoServer Get a reference to the specified…
MongoDB add, delete, modify
Introduction to MongoDB driver types 1. MongoDB official driver: mongo-csharp-driver, download address: https://github.com/mongodb/mongo-csharp-driver/downloads 2. Third-party driver samus , this is a frequently used driver with a relatively fast update frequency. In addition to supporting general operations, the samus driver also supports Linq Introduction to MongoDB driver types 1. MongoDB official driver: mongo-csharp-driver, download address: https://github.com/mongodb/mongo-csharp-driver/downloads 2. The third-party driver samus is a commonly used driver with a relatively fast update frequency. In addition to supporting general operations, the samus driver also supports Linq and Lambda expressions. Download address: https://github.com/samus/mongodb-csharp. The operation process of the two mongodb drivers on the mongodb database is basically the same, but there are differences in the implementation methods. For example, the samus driver not only supports general formal operations, but also supports Linq and Lambda expressions. Use MongoDB official driver to operate the database Unzip the package and get the following two files: MongoDB.Bson.dll: Serialization, Json related MongoDB.Driver.dll: mongodb driver Add references and introduce the above two DLLs into the project Introducing namespaces into code using MongoDB.Bson; using MongoDB.Driver; Obtain database connection service string cOnnectionString= ” mongodb://localhost ” ; //mongodb://[username:password@]hostname[:port][/[database][?options]] MongoServer server = MongoServer.Create(connectionString); // Connect to a MongoServer Get a reference to the specified…
MongoDB add, delete, modify, query operation mongoose verification + set association
mongoose verification When creating a collection rule, you can set the validation rules for the current field. If validation fails, insert failure will be entered Commonly used validation rules provided within mongoose: required: true required field or [ true , ‘ Please enter ×× ‘ ] minlength: Minimum length of string maxlength Maximum length of string (error message can also be customized) trim: remove spaces on both sides of the string min: 2 The minimum value is 2 max: 100 The maximum value is 100 default: default value enum: enumerates the values that the current field can have Custom validator: validate: custom validator set association Usually there is a relationship between data in different collections. For example, article information and user information are stored in different collections, but the article is published by a user. To query all the information of the article including the publishing user, just Need to use collection association Associate collections using ids Use the populate method to query related collections Collection association implementation Case: Add, delete, modify and check user information