Tag Archives: NOSQL

How to insert ,update, delete into MongoDB NOSQL database with Python

How to insert ,update, delete into  MongoDB NOSQL database with  Python

Watch this 30 minute video to guide you through this process for my database for my trading system

 

How to insert update delete in a MongoDB NOSQL database with Python

 

Source code:

Query

#https://docs.mongodb.org/getting-started/python/query/

from pymongo import MongoClient

client = MongoClient()
# db = client.qln
# cursor = db.qln.find({"positions.shortsymbol": "ibm"})
#
# for document in cursor:
#     print(document)


db = client.qln
collection = db.equity

stocks = collection.find({"shortsymbol": "k"})

print stocks.count()
for stock in stocks:
    print(stock)

Insert

#https://docs.mongodb.org/getting-started/python/insert/
from pymongo import MongoClient

client = MongoClient()
db = client.qln

#db.equity.insert( { "_id": 5, item: "box", qty: 20 } )

# from datetime import datetime
result = db.equity.insert_one(
    { "idx" : 2,
      "shortsymbol" : "k",
      "shortentryts" : 1000,
      "shortentryprice" : 100,
      "shortstoplossper" : 0.08,
      "shortupstop" : 105.1,
      "shortlowstop" : 95.1,
      "shortsofttargperc" : 0.08,
      "shortuptarget" : 105.1,
      "showlowtarget" : 95.1,
      "longsymbol" : "pep",
      "longentryts" : 1000,
      "longentryprice" : 100,
      "longstoplossper" : 0.08,
      "longupstop" : "10.5.1",
      "longlowstop" : 95.1,
      "longsofttarget" : 0.08,
      "longuptarget" : 105.1,
      "longdowntarget" : 95.1,
      "shortexitts" : 1000,
      "shortexitprice" : 95.1,
      "longexitprice" : 105.1,
      "shortqty" : 1000,
      "longqty" : 1000,
      "shortbeta" : 0.95,
      "longbeta" : 1.01
    }

)
print result.inserted_id

#https://docs.mongodb.org/getting-started/python/query/
cursor = db.qln.find()

for document in cursor:
    print(document)


Update

 

#https://docs.mongodb.org/manual/reference/method/db.collection.update/
from pymongo import MongoClient

client = MongoClient()
db = client.qln

result = db.equity.update_one(
    {"shortsymbol": "k"},
    {"$set": {"shortentryprice": 107.5, "shortstoplossper": 1.40}}
)

print result.matched_count
print result.modified_count

Delete

 

#https://docs.mongodb.org/getting-started/python/remove/
from pymongo import MongoClient

client = MongoClient()
db = client.qln

result = db.equity.delete_many({"shortsymbol": "k"})

print result.deleted_count

Video links thread on Online Meetup LIVE Event: NOSQL vs SQL database smackdown, which one for what?

Video links thread  on Online Meetup LIVE Event: NOSQL vs SQL database smackdown, which one for what?

There are so many databases usedbut what for what reason. I really want to investigate this with others online. If you are interested in our poll on this on popularity, please, visit:

http://quantlabs.net/surveys/tick-db/

This should also cover the experience with pros and cons of operating systems as well including Windows, Linux, or Mac OSX.

When? Dec 15 at 7 PM EST

This will be delivered online via Goto Meeting. Also note as will there will no playback other than for Quant Elite members after this LIVE event.

LIVE Event: NOSQL vs SQL database smackdown, which one for what?

Monday, Dec 15, 2014, 7:00 PM

13 Members Went

Check out this Meetup →

 

Continue reading

Will Microsoft OpenTech put Redis into #1 status for in memory NOSQL database? For Linux, Window, and Mac OS X?

Wow! I almost crapped my pants when I read these links:

http://www.zdnet.com/blog/microsoft/microsoft-makes-improvements-to-redis-on-windows-in-memory-database/12563
http://stackoverflow.com/questions/6476945/how-do-i-run-redis-on-windows
https://github.com/rgl/redis/downloads  <–best download
http://blogs.msdn.com/b/interoperability/archive/2012/04/26/here-s-to-the-first-release-from-ms-open-tech-redis-on-windows.aspx
https://github.com/MSOpenTech/Redis

The amazing thing is Microsoft Azure is now the #1 division within Microsoft thanks to their new adoption of the open source languages like Python, Java, Ruby, PHP, etc. Now they want to move into NOSQL databases like Redis. This is big.

Anyhow, I tried getting MongoDB running on a multiplatform within a cluster. What a nitemare thanks to the very primitive documentation. It was rendered useless! As you know, I am now able to see my $100K saving as I switch from Matlab to R. It was so easy to do with Redis for Windows. Compared to MongoDB with a clusters was well useless. Junk. Dead on arrival compared to Redis.Well at least compared to my needs.

As with Redis available for Windows, it can be instantly installed as a service which makes it very easy to start. The GitHub.com link will get you there. I was able to connect into the Redit repository so simply with doRedis.R package.

Watch this Youtube at this link to learn more: http://bigcomputing.com/doredis.html

For clustering and parallelization from R’s perspective is so simple. Scary simple. Compare to MongoDB. Ugly as hell.I can say without hesitation, this is the best stack to go with or my needs. No more wasted days with MongoDB and MYSQL. Too bad they don’t understand how to properly document compared to doRedis and the Redis comminity. I can now move forward onto other steps without worrying about broken stuff from the other options I thought I had to tackle!

I can assure you my Premium membership would expext nothing less of me to deliver. Also, as Borat would say. Very nice!

As in the Youtube video, register your subsequent doRedis R jobs in the host Redis but doing within your secondary R environment: redisWorker(host=’192.168.1.10′,queue=’jobs’) where you register to the host id with the queue being run.

[youtube_sc url=”http://www.youtube.com/watch?v=RtbAk-n-tqM” title=”NOSQL%20Redis%20on%20Windows%20and%20Linux%20clusterto%20parallelize%20with%20R%20and%20doRedis%20package”]