Posts

Showing posts with the label Javascript

Performance benchmark your code

I stumbled upon this site, http://jsben.ch/hyj65 basically it's allowing you to compare your code side by side with variations of the code and see the speed of it and calculate performance gain on the fly.

MongoDB tip: 4 ways to modify replica set configuration

This is just a quick guide on how to modify your replica set settings in 4 different ways. This guide is assuming you have a functional replica set ready, it doesn't matter if it's a single node or multi-node replica set. In each of the four method, I am looking to modify the priority of the _id=0 node Method 1: Via Mongo Shell Login to your Mongo shell,  simply type in mongo , assuming default port is being used and authentication is not enabled [in Mongo shell] cfg = rs.conf() cfg.members[0].priority=99 rs.reconfig(cfg) # "ok":1 indicates the new configuration has been set  MongoDB Enterprise minvera:PRIMARY> rs.reconfig(cfg) {         "ok" : 1,         "operationTime" : Timestamp(1528464949, 1),         "$clusterTime" : {                 "clusterTime" : Timestamp(1528464949, 1),             ...

MongoDB tip, identify and convert type of a specific field

Image
I found this post when I encountered some type issue and the better solution seems to be to convert the type in place. So I just did a quick experiment myself to make sure it works properly. to set up this experiment, first run db.testConvert.insert({typeField:NumberLong(1)}); db.testConvert.insert({typeField:NumberInt(1)}); db.testConvert.insert({typeField:1}); We verify now typeField has contain all three types, Int64, Int32, and Double Referencing from BSON type documentation, we know that Double is 1. Then we run the following var bulk = db.testConvert.initializeUnorderedBulkOp(), count=0; db.testConvert.find({"typeField":{"$type":1}}).forEach(function(doc) {     bulk.find({"_id":doc._id}).updateOne({         "$set":{"tmpField":NumberLong(doc.typeField.valueOf())},         "$unset":{"typeField":1}     });     bulk.find({"_id": doc._id}).updateOne({ "$rename": { ...