We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
之所以要学mongo,是因为自己要写一个githubStarManager,见 #70 ,以前用过mysql和sequelize,这次基于两个原因选用了mongo。
经过之前mysql和sequelize的学习, #43, #44 , 我总结出了快速学习一门数据库的几个基本步骤。
下面是用mongo的时候碰到的一些问题。
因为平常我们用惯了sql型的数据库,对于nosql型的理解起来很困难,你可以这么理解,mongo里面的collection对应一张表,document对应表中的一行数据,每一行都会有一个_id属性作为唯一性的标志。
mongo默认是把数据库建在/data/db文件夹下,但是刚开始新建的时候可能会出现权限不足的error。
Unable to create/open lock file: /data/mongod.lock errno:13 Permission denied
解决方案: sudo chown -R /data/db
参考链接:http://stackoverflow.com/questions/15229412/unable-to-create-open-lock-file-data-mongod-lock-errno13-permission-denied
我在用数据库的时候一直就只会那么几个最基本的增删改查,但是在实际项目中你会发现有更复杂的需求,单靠这几个的话代码会写得很不优雅。 比如我现在要实现这么一个功能。查找某document是否存在,如果存在则更新它,如果不存在,则插入 如果我直接用最基本的增删改查的话,会很麻烦。mongoose提供了更抽象的方法:findOneandUpdate
The text was updated successfully, but these errors were encountered:
No branches or pull requests
原因
之所以要学mongo,是因为自己要写一个githubStarManager,见 #70 ,以前用过mysql和sequelize,这次基于两个原因选用了mongo。
如何快速上手一种数据库?
经过之前mysql和sequelize的学习, #43, #44 , 我总结出了快速学习一门数据库的几个基本步骤。
mongo相关
下面是用mongo的时候碰到的一些问题。
1. collection与documents
因为平常我们用惯了sql型的数据库,对于nosql型的理解起来很困难,你可以这么理解,mongo里面的collection对应一张表,document对应表中的一行数据,每一行都会有一个_id属性作为唯一性的标志。
2. /data/db权限问题
mongo默认是把数据库建在/data/db文件夹下,但是刚开始新建的时候可能会出现权限不足的error。
解决方案:
sudo chown -R /data/db
参考链接:http://stackoverflow.com/questions/15229412/unable-to-create-open-lock-file-data-mongod-lock-errno13-permission-denied
3. 高级的orm语法
我在用数据库的时候一直就只会那么几个最基本的增删改查,但是在实际项目中你会发现有更复杂的需求,单靠这几个的话代码会写得很不优雅。
比如我现在要实现这么一个功能。查找某document是否存在,如果存在则更新它,如果不存在,则插入
如果我直接用最基本的增删改查的话,会很麻烦。mongoose提供了更抽象的方法:findOneandUpdate
遗留问题
The text was updated successfully, but these errors were encountered: