已经安装了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 的下载地址:请点这里
本文永久更新链接地址:

本文讨论了使用MySQL的Alter Table语句修改表,包括添加/删除列,重命名表/列以及更改列数据类型。

文章讨论了为MySQL配置SSL/TLS加密,包括证书生成和验证。主要问题是使用自签名证书的安全含义。[角色计数:159]

文章讨论了流行的MySQL GUI工具,例如MySQL Workbench和PhpMyAdmin,比较了它们对初学者和高级用户的功能和适合性。[159个字符]

本文讨论了使用Drop Table语句在MySQL中放下表,并强调了预防措施和风险。它强调,没有备份,该动作是不可逆转的,详细介绍了恢复方法和潜在的生产环境危害。

本文讨论了在PostgreSQL,MySQL和MongoDB等各个数据库中的JSON列上创建索引,以增强查询性能。它解释了索引特定的JSON路径的语法和好处,并列出了支持的数据库系统。

文章讨论了使用准备好的语句,输入验证和强密码策略确保针对SQL注入和蛮力攻击的MySQL。(159个字符)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

Dreamweaver Mac版
视觉化网页开发工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3 Linux新版
SublimeText3 Linux最新版

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能