Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ MongoDB learning Notes (2) basic connection example of -Nodejs and MongoDB     - Puppet 3.x installed on Debian 7 (Server)

- Vim configuration instructions (Linux)

- installation and configuration of the PHP environment (Apache2) under Linux (Server)

- Python several standard types of built-in functions (Programming)

- Linux System Tutorial: How to browse the Linux command line, weather forecast (Linux)

- Ubuntu 12.04 kernel configuration automatically restart and crash dump (Linux)

- How to use the Vault secure password storage and API key (Linux)

- Linux commands with browsing and downloading files (Linux)

- The REVERSE function of DB2 (Database)

- PLSQL often lose resolution process automatically disconnect the connection (Database)

- Java inheritance initialization problem (Programming)

- Linux operation and maintenance of the automated installation and deployment RHEL7.0 Cobbler (Linux)

- Red Hat Enterprise Linux configuration VNC multi-user access methods (Linux)

- 8 Git tips (Linux)

- open V switch port mirror in OpenStack neutron (Server)

- ActiveMQ memory settings and flow control (Linux)

- MySQL import large amounts of data (Database)

- The basic principle of pointers in C ++ (Programming)

- Linux Network Programming - raw socket programming (Programming)

- Some MySQL interview questions (Database)

 
         
  MongoDB learning Notes (2) basic connection example of -Nodejs and MongoDB
     
  Add Date : 2018-11-21      
         
         
         
  Premise

Node.js already installed and MongoDB, node.js used herein is v0.12.0, MongoDB is 3.0.0.

Initialization data

Start the MongoDB service, insert a test instance data in the database:

db.user.install ({name: "scaleworld", age: 27});
Node.js modules introduced in MongoDB

npm install mongodb
Write mongodbDemo.js

var mongodb = require ( 'mongodb');
var server = new mongodb.Server ( "localhost", 27017, {safe: true});
new mongodb.Db ( 'test', server, {}). open (function (error, client) {
    if (error) throw error;
    var collection = new mongodb.Collection (client, 'user');
    collection.find (function (error, cursor) {
        cursor.each (function (error, doc) {
            if (doc) {
                console.log ( "name:" + doc.name + "age:" + doc.age);
            }
        });
    });
});
run

{[Error: Can not find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND'}

js-bson: Failed to load c ++ bson extension, using pure JS version
================================================== ==============================
Please ensure that you set the default write concern for the database by setting =
= One of the options =
= =
= W: (value of> -1 or the string 'majority'), where <1 means =
= No write acknowlegement =
= Journal: true / false, wait for flush to journal before acknowlegement =
= Fsync: true / false, wait for flush to file system before acknowlegement =
= =
= For backward compatibility safe is still supported and =
= Allows values ​​of [true | false | {j: true} | {w: n, wtimeout: n} | {fsync: true}] =
= The default value is false which means the driver receives does not =
= Return the information of the success / error of the insert / update / remove =
= =
= Ex: new Db (new Server ( 'localhost', 27017), {safe: false}) =
= =
= Http://www.mongodb.org/display/DOCS/getLastError+Command =
= =
= The default of no acknowlegement will change in the very near future =
= =
= This message will disappear when the default safe is set on the driver Db =
================================================== ======================================
name: scaleworld age: 27
 
While the final print out before we insert data, but in front of a bunch of people looking uncomfortable or wrong, we have to eliminate them.
Error: Can not find module '../build/Release/bson' solutions

{[Error: Can not find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND'}

js-bson: Failed to load c ++ bson extension, using pure JS version
The first two lines say is not found bson module. We flew installation easier:

npm install bson
Then D: \ nodejsdemo \ node_modules \ mongodb \ node_modules \ bson \ ext \ index.js in bson = require ( '../ build / Release / bson') into bson = require ( 'bson'), re-run .

However, this problem is solved only the first two lines, as well as with = surrounded problem.

"Please ensure that you set the default write concern for the database" solution

From the last sentence "This message will disappear when the default safe is set on the driver Db" we can see a solution to this problem, as long as the database connection to be secure.
     
         
         
         
  More:      
 
- The Java ThreadLocal (Programming)
- Binding unofficial Google Drive and Ubuntu 14.04 LTS (Linux)
- CentOS yum install LNMP PHP5.4 version (Server)
- Oracle Database Performance Optimization of memory disk (Database)
- Using Linux command line and execute PHP code (Programming)
- CentOS 6.6 x64 Oracle Database 11gR2 RAC automated installation scripts (Database)
- Linux, set and view environment variables (Linux)
- The formatted Linux hard drive and mount (Linux)
- Java factory pattern (Factory mode) (Programming)
- MyEclipse configuration necessary (Linux)
- Netcat Example (Linux)
- Ubuntu Linux installation GAMIT10.6 (Linux)
- MD5 and simple to use (Linux)
- LVM management parameters commonly used commands explained in detail (Linux)
- Oracle 11g maintenance partitions (eight) - Renaming Partitions (Database)
- count (*) function in MySQL optimization of InnoDB storage engine (Database)
- Json Applications of FastJson (Programming)
- Ubuntu 14.04 / Linux Mint 17 How to install the MintMenu 5.5.2 menu (Linux)
- Java look and feel mode (Facade mode) (Programming)
- Access.log Apache access log analysis and how to import it into MySQL (Server)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.