Search This Blog

Showing posts with label mongodb. Show all posts
Showing posts with label mongodb. Show all posts

Tuesday, November 28, 2017

Cassandra Group By clause in Select command

1. Go to C:\Program Files\DataStax-DDC\apache-cassandra\conf\cassandra.yaml
change false to true

enable_user_defined_functions: true


2. Paste below functions in cqlsh window

CREATE OR REPLACE FUNCTION state_group_and_count( state map, type text )
CALLED ON NULL INPUT
RETURNS map
LANGUAGE java AS '
Integer count = (Integer) state.get(type);  if (count == null) count = 1; else count++; state.put(type, count); return state; ' ;

CREATE OR REPLACE AGGREGATE group_and_count(text)
SFUNC state_group_and_count
STYPE map 
INITCOND {};


3. execute the query like below

--select group_and_count(column) from table;
-- ex
-- select group_and_count(item) from skutable;



4. you may see like this 
Failed to format value OrderedMapSerializedKey([(u'xxx', 4)]) : 'NoneType' object has no attribute 'sub_types'
this is a cqlsh error. so you can try from programming languages like java..., it may work perfectly.

Thursday, December 10, 2015

Add - Remove Column in MongoDB


// add new column and with default value
db.order.update({}, {$set: {"status": 'NEW'}},{multi:true})

//remove a column
db.order.update({}, {$unset: {"status": ''}},{multi:true})

MongoDB - Update statement

//update
db.documentName.update({'_id': ObjectId('566136f3e4b03044bfb8b37e'),'attributeName':'existing-value'},{$set:{'sameAttributeName':'New-value'}})

sample

db.order.update({'_id': ObjectId('566136f3e4b03044bfb8b37e'),'status':'NEW'},{$set:{'status':'COMPLETE'}})







db.login.update({'_id': ObjectId('5667a7ffe4b04ebafe56122e'),'password':'','email':'','mobileNumber':''},{$set:{'password':'qwerty','email':'drvijayy2k2@gmail.com','mobileNumber':'9842088860'}})

MongoDB Install in Linux

1.    Install MongoDB
    Import the public key used by the package management system.

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

2. Create a list file for MongoDB.

    echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

3 Reload local package database.

    sudo apt-get update

4 Install the MongoDB packages.

    sudo apt-get install -y mongodb-org

4.1 Install a specific release of MongoDB.

    sudo apt-get install -y mongodb-org=3.0.7 mongodb-org-server=3.0.7 mongodb-org-shell=3.0.7 mongodb-org-mongos=3.0.7 mongodb-org-tools=3.0.7

5. Start MongoDB.


    sudo service mongod start

5.1 Verify that MongoDB has started successfully
    Verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading

6 Stop MongoDB.

    sudo service mongod stop

7 Restart MongoDB.
   
    sudo service mongod restart

8. mongodb - uninstall

    sudo service mongod stop
    sudo apt-get purge mongodb-org*
    sudo rm -r /var/log/mongodb
    sudo rm -r /var/lib/mongodb

Hit Counter


View My Stats