Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ MongoDB learning Notes (2) basic connection example of -Nodejs and MongoDB     - C # assembly calls across constants, variables and functions (Programming)

- Use $ BASH ENV variable to mention the right way under Linux (Linux)

- Ubuntu 14.04 kernel after the restart boot black screen to solve (Linux)

- JavaScript object - Flexible and dangerous (Programming)

- ORA-27054 NFS problem solving (Database)

- Ubuntu 15.04 / 14.04 install Ubuntu After Install 2.6 (Linux)

- CentOS 6.5 install Firefox (Linux)

- Install VMware Tools in Debian (Linux)

- Vim configuration instructions (Linux)

- Hibernate Search 5.5 in the search results sorted (Linux)

- Linux Getting Started Tutorial: / var / spool / clientmqueue fill the root directory (Linux)

- Oracle: RETURNING clause (Database)

- Ubuntu Linux use MAC binding against ARP attacks (Linux)

- OpenStack image production in the CentOS 6.2 (Linux)

- J2EE Example of Filter (Programming)

- Linux shell script to adjust the Task Scheduler (Linux)

- Manage SQL Server services login (start) account and password (Database)

- Unix system security configuration (Linux)

- CentOS7 management of systemd (Linux)

- How to override the plain text files and directories soft connection in linux (Linux)

 
         
  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:      
 
- Scope of variables in Object-C (Programming)
- Detailed installation of CentOS 6.x (Linux)
- Analysis of common mistakes when compiling MySQL installation (Database)
- Oracle large table to clean truncate .. reuse storage (Database)
- Lsblk command lists using Linux block device information (Linux)
- Keepalived achieve high availability Nginx Reverse Proxy (Server)
- Scope of variables in C # (Programming)
- After installation of Debian 6.0 do a few things first (Linux)
- Linux Network Security Tips Share (Linux)
- Which file system is most suitable for your Linux system (Linux)
- ORA-38856: Unable instance UNNAMED_INSTANCE_2 (redo thread 2) marked enabled (Database)
- Use the top command (Linux)
- Java application server WildFly (Server)
- Apache Linux firewall reverse proxy configuration (Linux)
- Thinking in Java study notes - initialization and cleanup (Programming)
- Redis master-slave replication switch (Database)
- Httpclient4.4 of principle (Http execution context) (Programming)
- Install KVM on Ubuntu and build a virtual environment (Linux)
- How to Set Free SSH password on CentOS / RHEL (Linux)
- MySQL 5.6 database code changes (Database)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.