Skip to content

Instantly share code, notes, and snippets.

@asya999
asya999 / mydb_files
Last active January 3, 2016 04:59
files
16M /data/db/mydb.ns
64M /data/db/mydb.0
128M /data/db/mydb.1
@asya999
asya999 / put_in_data
Created January 14, 2014 04:42
Messing with DB
mydb@PRIMARY(2.5.5-pre-) > for (i=0;i<1000;i++) db.bar.insert({})
Insert WriteResult({ "ok" : 1, "n" : 1, "lastOp" : Timestamp(1389674231, 506) })
mydb@PRIMARY(2.5.5-pre-) > db.createCollection("cap",{capped:true,size:1024*1024*1024})
{ "ok" : 1 }
mydb@PRIMARY(2.5.5-pre-) > db.stats(1024*1024)
{
"db" : "mydb",
"collections" : 6,
"objects" : 1015,
"avgObjSize" : 24.28768472906404,
@asya999
asya999 / delete_files
Last active January 3, 2016 04:59
Delete data files
asyasmacbook:tests asya13$ rm /data/db/mydb.[12]
asyasmacbook:tests asya13$ ls -1shtr /data/db/mydb.*
16M Jan 13 20:37 /data/db/mydb.ns
64M Jan 13 20:37 /data/db/mydb.0
asyasmacbook:tests asya13$ ps ax | grep mongod | grep -v grep | awk '{print $1}'
65176
asyasmacbook:tests asya13$ lsof -p 65176
mongod 65176 asya13 txt REG 1,2 16777216 3984323 /data/db/mydb.ns
mongod 65176 asya13 txt REG 1,2 67108864 3984324 /data/db/mydb.0
mongod 65176 asya13 txt REG 1,2 134217728 3984325 /data/db/mydb.1
@asya999
asya999 / dbrepair
Created January 14, 2014 05:02
repair time
mydb@PRIMARY(2.5.5-pre-) > db.repairDatabase()
{ "ok" : 1 }
mydb@PRIMARY(2.5.5-pre-) > db.stats(1024*1024)
{
"db" : "mydb",
"collections" : 6,
"objects" : 1015,
"avgObjSize" : 24.33103448275862,
"dataSize" : 0,
"storageSize" : 1024,
@asya999
asya999 / noHAconf
Created January 16, 2014 00:38
ReplicaSet
test@test:PRIMARY(2.4.8) > rs.conf()
{
"_id" : "test",
"version" : 5,
"members" : [
{
"_id" : 0,
"host" : "asyasmacbook.local:40001"
},
{
@asya999
asya999 / aggAndResult
Last active August 29, 2015 14:01
findingACharacter
> db.substring.aggregate({"$project":{"_id":0, "machine":1, "shortName":{"$substr":[field,array[searchStart],999]}}})
{ "machine" : "foo.apple.com", "shortName" : "apple.com" }
{ "machine" : "bar.facebook.com", "shortName" : "facebook.com" }
{ "machine" : "baz.mongodb.org", "shortName" : "mongodb.org" }
@asya999
asya999 / sample docs
Created May 14, 2014 21:37
Sample Docs
> db.substring.find({},{_id:0,machine:1})
{ "machine" : "foo.apple.com" }
{ "machine" : "bar.facebook.com" }
{ "machine" : "baz.mongodb.org" }
function cleanUpLong(max_running_secs) {
var currentOps = db.currentOp({
$and: [
{ op: "query" },
{ msg: { $exists: false } }, // not a sharding operation!
{ secs_running: { $gt: max_running_secs } },
{"ns": "backstage.action_loc" }
]
});
currentOps.inprog.forEach(function (op) {
db.createCollection( "email", { storageEngine: {
wiredTiger: { configString: "block_compressor=zlib" }}})
> db.mixedTypes.find()
{ "_id" : ObjectId("55a5761b377e8e01062a12ab"), "f1" : 1 }
{ "_id" : ObjectId("55a57622377e8e01062a12ac"), "f1" : "1.000" }
{ "_id" : ObjectId("55a57630377e8e01062a12ad"), "f1" : { "field" : 1 } }
{ "_id" : ObjectId("55a5763d377e8e01062a12af"), "f1" : ObjectId("55a5763d377e8e01062a12ae") }
{ "_id" : ObjectId("55a57644377e8e01062a12b0"), "f1" : true }
{ "_id" : ObjectId("55a57647377e8e01062a12b1"), "f1" : false }
{ "_id" : ObjectId("55a57651377e8e01062a12b2"), "f1" : ISODate("2015-07-14T20:51:29.324Z") }
{ "_id" : ObjectId("55a57659377e8e01062a12b3"), "f1" : null }
{ "_id" : ObjectId("55a57675377e8e01062a12b4"), "f1" : 1 }