Skip to content

korkeatw/node-mongodb-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node MongoDB Stream

Streams data in capped collection and push to client.

Installation

sudo apt-get install nodejs

If you install Node.js via apt-get you can run Node.js application using nodejs command. Sometime, some module run as Bash Shell that use node command, you may create symbolic link from nodejs to node to avoid command not found error.

git clone https://github.com/khasathan/nodejs-mongodb-stream.git

Set up environments

Nodejs

Install requires modules for this project. you can use NPM (Nodejs Package Manager)

cd node-mongodb-stream
npm install

NPM will be install specific modules in package.json file. After install you should have node_modules directory.

MongoDB

Collection we will use MUST BE capped collection so it's use stream feature. You can create capped collection by mongodb command

db.createCollection('col_name', { capped : true, size : 100000, max : 10 });

Or you want to convert exist collection to capped

db.runCommand({'convertToCapped' : 'col_name', size : 100000, max : 10 });

Check the collection you create is capped

db.col_name.isCapped();

options

  • capped (boolean) set collection to capped
  • size (int) size of colleciton in byte
  • max (int) max document in collection

NOTE: The capped collection provide to use in some case like real-time push service. It's NOT used for data storage because old data in capped collection will be deleted automatically. If you want store data, you can insert data into general collection too. See MongoDB document about Capped Collection here http://docs.mongodb.org/manual/core/capped-collections

Running and testing app

  • Start Mongodb first
  • Running Nodejs server
cd node-mongodb-stream
node app.js
  • Open index.html in web browser
  • Insert document into MongoDB message should be appear in browser

About

Streaming data in collection and push to client.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published