如何为应用程序的用户使用2个集合用于不同类型的数据

时间:2016-01-15 01:21:27

标签: javascript mongodb express mongoose passport.js

我想制作像<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> <div class="container"> <div class="row mySpecialRow"> <div class="col-sm-8 yellow"> <p>2Pinterest brunch meh normcore. Umami quinoa cray, paleo plaid tousled hoodie hella hammock authentic cliche beard. Chillwave bitters master cleanse, celiac authentic pitchfork microdosing truffaut mustache vice portland distillery skateboard 3 wolf moon butcher. Banh mi keytar disrupt heirloom, retro selvage slow-carb 8-bit before they sold out. Chartreuse post-ironic everyday carry viral banjo dreamcatcher beard, you probably haven't heard of them craft beer trust fund mixtape authentic VHS cardigan. Crucifix messenger bag biodiesel, fixie pork belly ugh dreamcatcher kinfolk vice roof party twee paleo franzen leggings. Yuccie wayfarers jean shorts semiotics try-hard craft beer mustache, synth forage brunch asymmetrical.</p> <p>Gastropub blog small batch, +1 keytar lomo mumblecore aesthetic. Authentic affogato meggings master cleanse, blue bottle 8-bit church-key tumblr shoreditch occupy readymade photo booth raw denim. Typewriter truffaut retro, shabby chic heirloom letterpress pitchfork four loko offal distillery fap drinking vinegar cold-pressed. Chillwave trust fund small batch dreamcatcher hammock single-origin coffee deep v meditation, tattooed portland fanny pack fixie wayfarers try-hard. Austin +1 mustache, waistcoat paleo stumptown blue bottle kombucha fashion axe raw denim pinterest shabby chic iPhone vinyl. Tattooed pug viral celiac. Fixie helvetica food truck affogato, offal scenester fashion axe.</p> <p>Gastropub blog small batch, +1 keytar lomo mumblecore aesthetic. Authentic affogato meggings master cleanse, blue bottle 8-bit church-key tumblr shoreditch occupy readymade photo booth raw denim. Typewriter truffaut retro, shabby chic heirloom letterpress pitchfork four loko offal distillery fap drinking vinegar cold-pressed. Chillwave trust fund small batch dreamcatcher hammock single-origin coffee deep v meditation, tattooed portland fanny pack fixie wayfarers try-hard. Austin +1 mustache, waistcoat paleo stumptown blue bottle kombucha fashion axe raw denim pinterest shabby chic iPhone vinyl. Tattooed pug viral celiac. Fixie helvetica food truck affogato, offal scenester fashion axe.</p> </div> <div class="col-sm-4 red"> <p>1Hella twee portland selvage, chicharrones tilde small batch. Wayfarers waistcoat stumptown you probably haven't heard of them quinoa, authentic marfa cronut aesthetic single-origin coffee fixie 3 wolf moon migas franzen. You probably haven't heard of them mixtape microdosing letterpress fingerstache before they sold out. 3 wolf moon keytar kale chips fixie, put a bird on it yuccie slow-carb street art hashtag green juice franzen kickstarter post-ironic. Bushwick franzen kickstarter taxidermy pickled scenester +1 kitsch, seitan occupy normcore brooklyn kinfolk. Migas pop-up bitters hammock. Knausgaard kale chips occupy, tacos iPhone truffaut fanny pack wolf yr.</p> </div> <div class="col-sm-4 green"> <p>3Street art cred godard normcore. Etsy tousled 3 wolf moon fashion axe try-hard. Four loko 3 wolf moon shoreditch, bespoke trust fund pug artisan gentrify seitan DIY literally selvage PBR&B pork belly kickstarter. Paleo jean shorts thundercats, butcher literally sartorial intelligentsia tacos. Fashion axe tofu YOLO, trust fund flexitarian tattooed mustache yr twee iPhone typewriter mixtape wayfarers cred. Blog art party next level everyday carry hoodie, cardigan iPhone cred yuccie kogi shabby chic meh ennui craft beer farm-to-table. Brunch cliche gastropub austin, paleo cornhole shoreditch jean shorts pabst polaroid.</p> </div> </div> </div>这样的集合。这代表医生登录信息。我相信我可以通过做这样的事情在注册时创建它:

{username : "jack", password : "pass"}

上面会创建一个名为doctor的集合,并通过下面的表单填写表格中的数据。

var Doctor = mongoose.model("doctor", authSchema);
module.exports = Doctor;

我想我可以为医生提供1个收集,为患者提供另一个收集。所以我可以创建一个部分,以便他们可以编辑他们的办公室的配置文件,另一个部分将患者添加到数据库中。 如何关联这两个系列。考虑到他们必须使用当地护照登记,他们只能看自己的病人。可能是我可以创建一个链接,说明查看患者,当他们点击它时,我会使用护照app.post("/signup", function(req, res){ Doctor.create({username: req.body.username , password : req.body.password}) res.redirect("/login"); }) 找到()所有患者。这是怎么做的。我自己学习这个,从未使用过2个系列,我不知道自己是否会走上正轨。

1 个答案:

答案 0 :(得分:0)

您可以使用这样的模型:

 var doctor = new Doctor();
 customer.username = req.body.username;
 password = req.body.password;
 doctor.save();

var doctor = new Doctor();
customer.username = req.body.username;
password = req.body.password;
doctor.save(function (err, doctor) {
      if (err) ..
 })

密码不应存储为纯文本,您可以使用bcrypt创建哈希,您可以找到如何保护密码的示例     https://github.com/asimzsaeed/mongodb_node_multi_tenancy_startup/blob/master/server/lib/services/user/model.js