Mongoose Operation MongoDB Notes (own notes, self-view)

Source: Internet
Author: User
Tags mongodb download

MongoDB Download/install

Mongoose NPM Install--save Mongoose

Mongoose Database connection

Const MONGOOSE = require (' Mongoose ')
Const Db_rul = ' MONGODB://LOCALHOST:27017/KOA2 '
Mongoose.connect (Db_rul, function (err) {if (err) {Console.warn (' Database connection failed: ' +err)}else{console.log (' database successfully connected to: ' +db_rul )}}) Module.exports = Mongoose Koa-router route NPM install--save koa-router Const router = require (' koa-router ') const body Parser = require (' Koa-bodyparser ')
Const MONGOOSE = require ('.. /config ')
Const ROUTER = new Router () http://cnodejs.org/topic/548e54d157fd3ae46b233502
Define Create data table
Create a schemaconst Createschema = Mongoose. Schema ({name: {type:string, required:true},age: {type:number, required:true}}) Const User = Mongoose.model (' users ', C Reateschema) Data Simple lookup User.find ({}, function (Err, doc) {Console.log (DOC)})
New User.create ({name: ' Afacode ', age:19 + Math.random ()}, function (Err, doc) {if (err) {Console.log (err)}else{ Console.log (DOC)}}) First this way

Mongoose Operation MongoDB Notes (own notes, self-view)

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.