Home > Article > Web Front-end > Amazing node.js reading notes: mongodb database interaction_node.js
This week’s study is mainly about nodejs database interaction, and we used jade template to build a user verification website. Mainly because I encountered a few problems.
1.mongodb version is too low
npm ERR! Not compatible with your operating system or architecture: mongodb@0.9.9
0.9.9 only supports linux, darwin, and freebsd systems, and the latest version supports wins.
2. After nodejs performs insert operation: Unable to read the result
The appearance is that the redirection failed. The real situation is that the insertion into the database has been successful but the doc is empty, not to mention the value of doc[0].email. The reason is that operations such as insert are performed asynchronously, and asynchronous operations do not return their results by default to determine whether the operation is successful. This function needs to be achieved by adding the third parameter {safe:ture}, that is, app.users.insert(req.body.user, {safe:ture}, function(){……}). In this way, the result is read successfully.
3. Undefined store appears in connect-connect
The source code is as above. The reason is found to be based on different versions of Express, and the connect-mongo module is introduced in different ways. There is also a special reminder in its Readme.md.
For different versions, just modify it accordingly.
4. Summary
After studying this book, I know some features of nodejs and active foreign language websites. The update frequency of some popular sections in node also increases the difficulty of learning. This book can be considered an introduction. Next, I plan to learn the sails back-end framework through actual combat. Problems encountered during study are also recorded in notebooks.