发布于 2015-09-14 14:40:16 | 466 次阅读 | 评论: 0 | 来源: 网络整理

You use Node.js to write event-driven, scalable network programs in server-side JavaScript. Node.js runs on Google’s V8. This section describes the available tools and suggested practices for using Node.js with MongoDB. For a more detailed discussion, see the Node.js Driver Manual.

The following are the README and source code:

Node.js Driver

The MongoDB Node.js driver is the 10gen-supported driver for MongoDB. In Spring 2012, 10gen officially adopted the popular Node MongoDB Native Project and sponsored the maintainer, Christian Kvalheim, to continue its development. It is written in pure JavaScript and provides a native asynchronous Node.js interface to MongoDB. The driver is optimized for simplicity. It can be used on its own, but it also serves as the basis of several object mapping libraries, such as Mongoose.

Install or Upgrade

The easiest way to install is to use npm:

npm install mongodb

Object Mappers

Because MongoDB is so easy to use, the basic Node.js driver can be the best solution for many applications. However, if you need validations, associations, and other high-level data modeling functions, then an Object Document Mapper may be helpful.

Mongoose

Mongoose is the 10gen-supported ODM for Node.js. It has a thriving open source community and includes advanced schema-based features such as async validation, casting, object life-cycle management, pseudo-joins, and rich query builder support.

Install it easily with npm:

npm install mongoose

The following are related resources:

Other Notable Projects

  • Mongoskin: Layer for node-mongodb-native.
  • Mongolia: Lightweight MongoDB ORM/driver wrapper.
  • Mongojs: Somewhat mimics the MongoDB shell api.

Each of these projects build on top of the native Node.js driver, and so some knowledge of that is useful, especially if you work with a custom MongoDB configuration.

3rd Party Drivers

A few 3rd party drivers exist. While not officially supported by 10gen, these drivers take a different approach that may be valuable given your needs.

  • node-mongodb <https://github.com/orlandov/node-mongodb>: An asynchronous Node interface to MongoDB, written in C.
  • Mongolian DeadBeef: A Node.js driver that attempts to approximate the MongoDB shell.
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务