node.js + mongodb应用程序的基本架构是什么? [英] What is the basic architecture of a node.js + mongodb app?
本文介绍了node.js + mongodb应用程序的基本架构是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在寻找没有运气的年龄.我在GitHub上找到了一些模块,但不幸的是,它们已经过时了.有谁知道node.js 0.6.x + mongodb的任何CRUD模块或教程吗?
I've been looking for ages with no luck. I found some modules on GitHub but unfortunately, were outdated. Does anyone know any CRUD module or tutorial for node.js 0.6.x + mongodb?
推荐答案
您可以尝试使用节点mongodb本机驱动程序; node-mongodb-native
You can try node mongodb native driver for it; node-mongodb-native
样本插入;
var mongodb = require('mongodb');
var server = new mongodb.Server("127.0.0.1", 27017, {});
new mongodb.Db('test', server, {}).open(function (error, client) {
if (error) throw error;
var collection = new mongodb.Collection(client, 'test_collection');
collection.insert({hello: 'world'}, {safe:true},
function(err, objects) {
if (err) console.warn(err.message);
if (err && err.message.indexOf('E11000 ') !== -1) {
// this _id was already inserted in the database
}
});
});
这篇关于node.js + mongodb应用程序的基本架构是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文