已经安装了node.js和MongoDB,本文使用的node.js是v0.12.0,MongoDB是3.0.0。
前提
已经安装了node.js和MongoDB,本文使用的node.js是v0.12.0,MongoDB是3.0.0。
MongoDB学习笔记(1)—在Windows系统中安装MongoDB
如何在CentOS 7安装Node.js
Ubuntu 14.04下搭建Node.js开发环境
Ubunru 12.04 下Node.js开发环境的安装配置
Node.Js入门[PDF+相关代码]
Node.js开发指南 高清PDF中文版 +源码
初始化数据启动MongoDB服务,在test数据库中插入一条实例数据:
db.user.install({name:"scaleworld",age:27});
在Node.js中引入MongoDB模块npm install mongodb
编写mongodbDemo.jsvar mongodb = require('mongodb'); var server = new mongodb.Server("localhost",27017,{safe:true}); new mongodb.Db('test',server,{}).open(function(error,client){ if(error) throw error; var collection = new mongodb.Collection(client,'user'); collection.find(function(error,cursor){ cursor.each(function(error,doc){ if(doc){ console.log("name:"+doc.name+" age:"+doc.age); } }); }); });
运行{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson: Failed to load c++ bson extension, using pure JS version ================================================================================ Please ensure that you set the default write concern for the database by setting = = one of the options = = = = w: (value of > -1 or the string 'majority'), where true/false, wait for flush to journal before acknowlegement = = fsync: true/false, wait for flush to file system before acknowlegement = = = = For backward compatibility safe is still supported and = = allows values of [true | false | {j:true} | {w:n, wtimeout:n} | {fsync:true}] = = the default value is false which means the driver receives does not = = return the information of the success/error of the insert/update/remove = = = = ex: new Db(new Server('localhost', 27017), {safe:false}) = = = = http://+Command = = = = The default of no acknowlegement will change in the very near future = = = = This message will disappear when the default safe is set on the driver Db = ======================================================================================== name:scaleworld age:27
虽然最后打印出了我们之前插入的数据,但是前面一大串的错误还是人看着不舒服,我们要消灭它们。 Error: Cannot find module '../build/Release/bson'的解决办法
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson: Failed to load c++ bson extension, using pure JS version
头两行说的是没有发现bson模块。好办我们立马安装:
npm install bson
然后将D:\nodejsdemo\node_modules\mongodb\node_modules\bson\ext\index.js中的bson = require('../build/Release/bson')改成bson = require('bson') ,重新运行。
不过这样只是解决头两行的问题,,还有用=包围起来的问题。
“Please ensure that you set the default write concern for the database”的解决办法从最后一句话“This message will disappear when the default safe is set on the driver Db”我们就可以看出该问题的解决办法,只要将数据库连接设置为安全即可。
具体代码修改如下:
new mongodb.Db('test',server,{})修改为new mongodb.Db('test',server,{safe:true})
Ubuntu 13.04下安装MongoDB2.4.3
MongoDB入门必读(概念与实战并重)
Ubunu 14.04下MongoDB的安装指南
《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF]
Nagios监控MongoDB分片集群服务实战
基于CentOS 6.5操作系统搭建MongoDB服务
MongoDB 的详细介绍:请点这里
MongoDB 的下载地址:请点这里
本文永久更新链接地址:

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
