说说你是怎么评价/使用mongodb的?用惯mysql再用mongo有点难受..
本人有LNMP经验,JS也比较熟练。接触node一个月左右,最近在看nodeclub的源码,发现自己对mongodb的使用很不习惯。 我知道每种语言,DB都有利弊,都是在权衡中设计出来的,大家都是过来人,都来分享下经验吧… 大家用mongodb:
- 是不是都不用联合查询之类的了,都是在应用层用代码实现?(mongoose好像是支持关系型的,不知道为什么nodeclub不使用)
- 是不是没法使用事务了?如何解决比较好?
- 像如下这种查询方式算不算很繁琐?对数据库的压力大不?
ep.all('has_read', 'unread', function (has_read, unread) {
[has_read, unread].forEach(function (msgs, idx) {
var epfill = new eventproxy();
epfill.fail(next);
epfill.after('message_ready', msgs.length, function (docs) {
docs = docs.filter(function (doc) {
return !doc.is_invalid;
});
ep.emit(idx === 0 ? 'has_read_messages' : 'hasnot_read_messages', docs);
});
msgs.forEach(function (doc) {
Message.getMessageRelations(doc, epfill.group('message_ready'));
});
});
Message.updateMessagesToRead(user_id, unread);
});
Message.getReadMessagesByUserId(user_id, ep.done('has_read'));
Message.getUnreadMessageByUserId(user_id, ep.done('unread'));
Message.getMessageRelations:
var getMessageRelations = exports.getMessageRelations = function (message, callback) {
if (message.type === 'reply' || message.type === 'reply2' || message.type === 'at') {
var proxy = new EventProxy();
proxy.fail(callback);
proxy.assign('author', 'topic', 'reply', function (author, topic, reply) {
message.author = author;
message.topic = topic;
message.reply = reply;
if (!author || !topic) {
message.is_invalid = true;
}
return callback(null, message);
}); // 接收异常
User.getUserById(message.author_id, proxy.done('author'));
Topic.getTopicById(message.topic_id, proxy.done('topic'));
Reply.getReplyById(message.reply_id, proxy.done('reply'));
} else {
return callback(null, {is_invalid: true});
}
};