万本电子书0元读

万本电子书0元读

顶部广告

Mongoose for Application Development电子书

售       价:¥

9人正在读 | 0人评论 9.8

作       者:Simon Holmes

出  版  社:Packt Publishing

出版时间:2013-08-26

字       数:97.9万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
This book is a mini tutorial full of code examples and strategies to give you plenty of options when building your own applications with MongoDB.This book is ideal for people who want to develop applications on the Node.js stack quickly and efficiently. Prior knowledge of the stack is not essential as the book briefly covers the installation of the core components and builds all aspects of the example application. The focus of the book is on what Mongoose adds to you applications, so experienced Node.js developers will also benefit.
目录展开

Mongoose for Application Development

Table of Contents

Mongoose for Application Development

Credits

About the Author

About the Reviewers

www.PacktPub.com

Support files, eBooks, discount offers and more

Why Subscribe?

Free Access for Packt account holders

Preface

What this book covers

What you need for this book

Who this book is for

Conventions

Reader feedback

Customer support

Downloading the example code

Errata

Piracy

Questions

1. Introducing Mongoose to the Technology Stack

The technology stack – Node.js, npm, MongoDB, and Express

The language and the server – JavaScript and Node

Single-threaded versus multithreaded

Blocking versus non-blocking code

JavaScript callbacks

Running the callback

A Node.js example

The database – MongoDB

The framework – Express

What Mongoose is all about

What is Mongoose good for?

What Mongoose is not ideally suited for

The cornerstones of Mongoose

Mongoose schemas

Mongoose models

Installing the full stack

Installing the prerequisites

Installing Node.js

Installing npm

Installing MongoDB

Installing Express.js

Installing Mongoose

Direct installation into project

Using project dependencies – package.json

Creating a project

Summary

2. Establishing a Database Connection

Mongoose default connection

Using multiple connections

About the connection string

Setting the port

Specifying a database user

Connection options

Closing the connection

Calling the close command

Closing when the Node process ends

Connection events

Connecting our project

Creating the connection

Catching the events

Opening the connection at application start

Creating the database

Summary

3. Schemas and Models

Introducing schemas

Field sizes

Data types allowed in schemas

String

Number

Date

Boolean

Buffer

ObjectId

Mixed

Tracking changes to Mixed type

Array

Warning – array defined as mixed type

Custom SchemaTypes

Where to write the schemas

Writing a schema

Modifying an existing schema

Setting a default value

Only allowing unique entries

Our final User schema

What's that "__v" thing?

Why is this needed?

Defining the Project schema

Improving the Project schema

Building models

Instances

Interacting with instances

Finding a single instance

Finding many instances

Considerations when choosing your model name

Setting the collection name

Overriding the collection name in the schema

Overriding the collection name in the model

Building models from our schemas

Our complete code

Summary

4. Interacting with Data – an Introduction

Model methods and instance methods

Setting up the project

Code structure

Adding the routes files

Tying the routes to Mongoose models

URLs and routes

Routes for user management

Routes for project management

Summary

5. Interacting with Data – Creation

Creating an instance

Adding data to the instance

Saving an instance

Using the saved data

Creating and saving database entry in one step

Chaining methods

The Model.create() method

CRUD – create data

Adding a new user form

Adding the Jade template

Linking the view to the URL

Adding the create user function

Error trapping

Creating a user session

Displaying the confirmation page

Try it out!

Adding create project functionality

Routes

New files and functions

Summary

6. Interacting with Data – Reading, Querying, and Finding

Approaches to find and read data

Using the QueryBuilder

Single query operation

Static helper methods – finding data

CRUD – reading user and project data

findOne() – finding a single user

Login form

Login action

Housekeeping – adding homepage links

Try it out!

find() – finding a list of projects and returning JSON to AJAX

Creating a new static find method

Setting up the route

Updating the view

Building the AJAX call

Try it out!

findByld() – finding a single project

Route setup

Creating the view

Summary

7. Interacting with Data – Updating

Model helper methods

Building the commands

Which method to choose

The catch

The three-step find-edit-save approach

CRUD – editing users and projects

Tracking user login

Editing the current user

Routes in use

Setting up the form

Setting up the controllers

Committing the edit

Editing projects

Routes

New files and functions

Summary

8. Interacting with Data – Deleting

Deleting data

CRUD – deleting user and projects

The "Are you sure" page

Deleting the user

Improving on this

Deleting individual projects

Routes

New files and functions

Summary

9. Validating Data

Mongoose validation – the basics

Default validators

All SchemaTypes

Number SchemaType

String SchemaType

Understanding validation errors

Doing it your way – create custom validation

Single function – no custom error message

Returning a custom error message

Validating a regular expression

Taking the messages out of the schema

Using multiple re-usable validators

Non-blocking, asynchronous validation

Extending Mongoose validation

Adding validation to our project

Summary

10. Complex Schemas

Population – references to other collections

Defining data for population

Saving population references

Retrieving populated data

Querying to return a subset of results

Populating into multiple parent items

Subdocuments

Creating subdocuments

Saving and validation

Retrieving subdocuments

Accessing a specific subdocument

Deleting subdocuments

Data management when modifying existing schemas

Summary

11. Plugins – Re-using Code

Reusable schema plugins

Creating a schema plugin

Applying the plugin to an existing schema

Using an external file

Using schema middleware

Not just for plugins

Sharing with the community

Summary

Index

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部