坚持路线和收藏。 Nodejs和mongodb

时间:2015-12-16 16:50:59

标签: node.js mongodb

我基本上有2个收藏。会议室和用户列表。我想一起显示房间清单和用户列表。我需要在名为" userlist"的页面中显示它。但它不起作用。如果我将收集保存在单独的页面中,它就可以了。

router.post('/adduser', function(req, res) {


var db = req.db;


var userName = req.body.username;
var userTime = req.body.usertime;
var userEmail = req.body.useremail;


var collection = db.get('usercollection');


collection.insert({
    "username" : userName,"usertime":userTime,
    "email" : userEmail
}, function (err, doc) {
    if (err) {

        res.send("There was a problem adding the information to the database.");
    }
    else {

   res.redirect("example");
    }
});
});

1 个答案:

答案 0 :(得分:0)

在您的问题中并不完全清楚,但如果您想在一个页面上拥有两个集合:

from django.db import models
from djangotoolbox.fields import ListField
from djangotoolbox.fields import EmbeddedModelField

class Post(models.Model):
    title = models.CharField(max_length = 200)
    text = models.TextField()
    tags = ListField()
    comments = ListField(EmbeddedModelField('Comment'))

    class MongoMeta:
        db_table = 'blogs_post'

class Comment(models.Model):
    created_on = models.DateTimeField(auto_now_add=True)
    author = EmbeddedModelField('Author')
    text = models.TextField()

class Author(models.Model):
    name = models.CharField(max_length = 150)
    email = models.EmailField()