1.url structure 2.The difference between http and http-restful lies in the assignment of mg_tls_opts 2.1 Distinguishing between http and https a) port address static const char *s_http_addr = “http://0.0.0.0:8000”; // HTTP port static const char *s_https_addr = “https://0.0.0.0:8443”; // HTTPS port b) Assign value to mg_tls_opts when using https struct mg_tls_opts opts = { #ifdef […]
Tag: mongoose
Using mongoose to operate the database in Mongodb and node.js
Directory 1. lowdb 2. What is MongoDB? 3. Mongodb core concepts 4. Download and use of Mongodb 5. Database and collection commands 5.1. Database commands 5.2. Collection command 5.3. Document commands 6. Mongoose 6.1. Insert document 6.2. Field type 6.3. Field value verification 6.3.1. Required items 6.3.2.Default value 6.3.3. Enumeration value 6.3.4. Unique value 6.4. […]
Solve the error report of MongoServerError: E11000 duplicate key error collection in Mongoose
Background Recently, I was developing a personal blog project based on express + mongoose, but this error occurred when adding new users: MongoServerError: E11000 duplicate key error collection: test.users index: username_1 dup key: {<!– –> username: “123abc” } Error analysis duplicate key error collection means that a duplicate key error has occurred in the database […]
Use the database Mongoose
Express Database Express apps can use all databases supported by Node (Express itself doesn’t support any specific behaviors/needs for database management). There are many popular choices, including PostgreSQL, MySQL, Redis, SQLite, and MongoDB. There are two ways to interact with the database: Use the database’s native query language (such as SQL) Use Object Data Model […]
Haike List – Level 1 and Level 2 Permission Increase – react-mongoose-react-redux
//backend const mongoose = require(‘mongoose’) mongoose.set(‘strictQuery’,true) mongoose.connect(‘mongodb://127.0.0.1:27017/db_zg4yk’) conn=mongoose.connection conn.on(‘open’,()=>{<!– –> console.log(‘Database connection succeeded’) }) conn.on(‘error’,err=>{<!– –> console.log(‘Database connection failed’) }) module.exports=mongoose //model.js const mongoose = require(‘./db’) const Schema = mongoose.Schema const listScheam=new Schema({<!– –> name: String, form:Array, browse:Number, sort:Number, isshow: Boolean, date: Date, children: Array, },{<!– –>versionKey:false}) let listModel = mongoose. model(‘list’, listScheam, ‘list’) module.exports={<!– […]
jianshu-react-mongoose/Addition and deletion of first-level authority and second-level authority
//backend //db.js const mongoose = require(‘mongoose’) mongoose.set(‘strictQuery’,true) mongoose.connect(‘mongodb://127.0.0.1:27017/db_jianshu’) conn=mongoose.connection conn.on(‘open’,()=>{<!– –> console.log(‘Database connection succeeded’) }) conn.on(‘error’,err=>{<!– –> console.log(‘Database connection failed’) }) module.exports=mongoose //model.js const mongoose = require(‘./db’) const Schema = mongoose.Schema const jianshuSchema=new Schema({<!– –> title: String, content: String, checked: Boolean, level:Number, pid:{<!– –> type:Schema.Types.ObjectId, ref:’jianshu’ } },{<!– –>versionKey:false}) let jianshuModel=mongoose.model(‘jianshu’,jianshuSchema,’jianshu’) // jianshuModel.create({<!– –> // […]
nodejs-mongoose
Learn about databases Relational database is a database based on the relational model. Data is stored in the form of table, each row in the table is a record, each column is a field, and each field has a data type. Relational databases use Structured Query Language (SQL) to query and manage data. Advantages: data […]
Detailed use of mongoose — how to build a server through mongoose
Preface It is better to teach people to fish than to teach people to fish. This article introduces in detail how to quickly understand and get started with mongoose for a rookie who has never heard of mongoose Some other open source libraries can learn with a similar approach Tools that need to be prepared […]
egg about the egg-mongoose method of operating the database
interface Model<T, TQueryHelpers = {<!– –>}, TMethods = {<!– –>}> extends NodeJS.EventEmitter, AcceptsDiscriminator {<!– –> new(doc?: AnyKeys<T> & AnyObject): EnforceDocument<T, TMethods>; aggregate<R = any>(pipeline?: any[]): Aggregate<Array<R>>; aggregate<R = any>(pipeline: any[], cb: Function): Promise<Array<R>>; /** Base Mongoose instance the model uses. */ base: typeof mongoose; /** * If this is a discriminator model, `baseModelName` is the […]
Database MongoDB; Object Document Model (ODM) library Mongoose
Database ? A database is a warehouse that organizes, stores and manages data according to its data structure. ? Our programs are all run in memory. Once the program finishes running or the computer is powered off, the data in the running program will be lost. ? So we need to persist some program running […]