Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ MongoDB learning Notes (2) basic connection example of -Nodejs and MongoDB     - To install Spotify in Ubuntu / Mint (Linux)

- The bulk batch multiple rows of data collect (Database)

- Java enum use (Programming)

- Java Builder mode (Programming)

- Open container cluster management system architecture and components introduced Kubernetes (Server)

- About DataGuard three protected mode test (Database)

- independently configurable PHP environment under CentOS6.5 (Server)

- Linux system crash (no such file or directory) How to rescue database (Linux)

- Ubuntu 15.10 install the latest Arduino IDE 1.6.7 (Linux)

- installation of Vim plugin YouCompleteMe under Ubuntu 15.04 (Linux)

- Gentoo: existing preserved libs problem solving (Linux)

- SVN common commands (Linux)

- Squid proxy server (Server)

- Introduction and use of the Raspberry Pi (Linux)

- Oracle bug Ora-04043 (Database)

- PHP call a Python program (Programming)

- Generic mechanism C11 standard (Programming)

- Make command tutorial (Linux)

- Linux processes in memory and memory cgroup statistics (Linux)

- Oracle background processes daemons (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:      
 
- C # dynamic class notes --- (Dynamic) Applications (Programming)
- Java reflection Introduction (Programming)
- Deepin Tutorial: Depth Description Installer expert mode (Linux)
- Android Studio Personalization (Linux)
- Linux package management operations Basic entry (Linux)
- Use ISO document production OpenStack used CoreOS mirror (Linux)
- Let MySQL 5.6 support Emoji expression (Database)
- How to override the plain text files and directories soft connection in linux (Linux)
- echo command (Linux)
- stat - Get more information than ls (Linux)
- JavaScript file loader LABjs API Explanation (Programming)
- MongoDB replication instance (Database)
- Elaborate .NET Multithreading: Thread Pool (Programming)
- Sort search algorithm Java - application examples with recursive dichotomy (Programming)
- About Linux operating system security (Linux)
- MongoDB 2.6 deployment replica set + partitions (Database)
- The default permissions for files and directories under Linux computing (Linux)
- Oracle GoldenGate tutorial Second, configure and use (Database)
- MySQL 5.5 on master-slave copy filter (Database)
- Installation and Configuration ISC DHCP server on Debian Linux (Server)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.