简体   繁体   English

Node.js-如何在Node.js中使用MongoDB公开/私有用户配置文件

[英]Node.js - How to make a user profile public/private using MongoDB in nodejs

I would like to create an application where the user can set private or public for their profile. 我想创建一个应用程序,用户可以在其中为自己的个人资料设置私有或公开。 May I know how can I do it with mongoDB with Nodejs? 我可以知道如何使用带有Node.js的mongoDB吗?

first include the npm for mongo npm install mongodb 首先包括用于mongo的npm install mongodb
In this example I also use monk npm install monk 在此示例中,我还使用和尚 npm install monk

var mongo = require('mongodb');
var monk = require('monk');
var db = monk('localhost:27017/nodetest1');

var collection = db.get('usercollection');
collection.update({_id:"123"}, {$set: {profileStatus:"public"}});

Note: That is the code for updating in the database. 注意:这是用于在数据库中更新的代码。 Before this you need to handle if the user wants to be public or private 在此之前,您需要处理用户是否要公开或私有

For more information lookup the nodejs mongodb driver and the npm site from mongodb 有关更多信息, 从mongodb查找nodejs mongodb驱动程序npm站点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM