Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //POZR MONGODB SERVICES CONNECTION STRING MOD033014
- // QUERY BASED ON SQL FILE CONTAINED IN SAMPLES FOLDER
- // IMPORT SQL INTO SQL DATABASE "db.pozr.in" THEN IMPORT INTO MONGODB
- var mongo = require('mongodb');
- var dbname = 'california';//YOUR POZR HANDLE
- var dbuser = 'pozr-username';//POZR-YOURNAME
- var dbkey = '';//PASSWORD GENERATED BY POZR SERVICES
- var server = new mongo.Server('no.pozr.in', 27017);
- db = new mongo.Db(dbname, server, {fsync:true});
- db.open(function(err, db) {
- if(!err) {
- console.log("Connected to database");
- db.authenticate(dbuser, dbkey, function(err, res) {
- if(!err) {
- console.log("Authenticated");
- //SPECIFIC COLLECTION
- var collection = db.collection('uCounter');
- //INSERT RECORD INTO COLLECTION
- var record = 'pozrapps' + Math.floor((Math.random()*100)+1);
- collection.insert({count_property: record}, function(docs) {
- var inserted = 'inserted into db -> ' + record;
- console.log(inserted);
- });
- //COUNT TOTAL RECORDS
- collection.count(function(err, count) {
- console.log("db contains -> " + count + " records.");
- });
- //RETREIVE ONE RESULT
- var query = { 'count_property' : 'java1' };
- collection.findOne(query, function(err, item) {
- console.log('viewing one record ->');
- console.log(item);
- });
- //RETREIVE ALL UNCOMMENT
- /*collection.find().each(function(err, doc) {
- if(doc != null) console.log("Doc from Each ");
- console.log(doc);
- });*/
- } else {
- console.log("Error in authentication.");
- console.log(err);
- }
- });
- } else {
- console.log("Error in open().");
- console.log(err);
- };
- });
- //READ MORE ABOUT THIS MODULE
- // http://mongodb.github.io/node-mongodb-native/contents.html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement