Output of my high lockTime and high page_faults value also - mongodb

we are using mongodb for our collections .
This is my stats of my development server .
My concerns are that there is high lockTime on my development server and also there are high page_faults value also .
Please tell me how can we resolve this ??
PRIMARY> db.serverStatus()
{
"host" : "ubsc-aio:27018",
"version" : "2.0.4",
"process" : "mongod",
"uptime" : 3278692,
"uptimeEstimate" : 3098346,
"localTime" : ISODate("2013-08-30T10:55:06.997Z"),
"globalLock" : {
"totalTime" : 3278692551767,
"lockTime" : 139516930214,
"ratio" : 0.0425526114483682,
"currentQueue" : {
"total" : 0,
"readers" : 0,
"writers" : 0
},
"activeClients" : {
"total" : 1,
"readers" : 1,
"writers" : 0
}
},
"mem" : {
"bits" : 64,
"resident" : 2009,
"virtual" : 23455,
"supported" : true,
"mapped" : 11420,
"mappedWithJournal" : 22840
},
"connections" : {
"current" : 162,
"available" : 7838
},
"extra_info" : {
"note" : "fields vary by platform",
"heap_usage_bytes" : 3645040,
"page_faults" : 4147570
},
"indexCounters" : {
"btree" : {
"accesses" : 902898,
"hits" : 901095,
"misses" : 1803,
"resets" : 0,
"missRatio" : 0.0019969033046922245
}
},
"backgroundFlushing" : {
"flushes" : 54639,
"total_ms" : 36709498,
"average_ms" : 671.8552316111203,
"last_ms" : 81,
"last_finished" : ISODate("2013-08-30T10:54:43.013Z")
},
"cursors" : {
"totalOpen" : 1,
"clientCursors_size" : 1,
"timedOut" : 7
},
"network" : {
"bytesIn" : 77779294441,
"bytesOut" : 314231714161,
"numRequests" : 189861092
},
"repl" : {
"setName" : "at",
"ismaster" : true,
"secondary" : false,
"hosts" : [
"localhost:27018",
"localhost:27017"
],
"arbiters" : [
"localhost:27019"
],
"primary" : "localhost:27018",
"me" : "localhost:27018"
},
"opcounters" : {
"insert" : 303294,
"query" : 133717078,
"update" : 59123588,
"delete" : 234256,
"getmore" : 48037783,
"command" : 125805489
},
"asserts" : {
"regular" : 0,
"warning" : 0,
"msg" : 0,
"user" : 16576,
"rollovers" : 0
},
"writeBacksQueued" : false,
"dur" : {
"commits" : 28,
"journaledMB" : 0.08192,
"writeToDataFilesMB" : 0.116123,
"compression" : 0.6743163821345669,
"commitsInWriteLock" : 0,
"earlyCommits" : 0,
"timeMs" : {
"dt" : 3000,
"prepLogBuffer" : 0,
"writeToJournal" : 25,
"writeToDataFiles" : 2,
"remapPrivateView" : 1
}
},
"ok" : 1
}

Related

mongodb: restore replicaset after kubernetes scaling down

I configured a replicatset correctly.
After having scaled down mongodb kubernetes pods, replicat set truned out to invalid status:
> rs.status();
{
"ok" : 0,
"errmsg" : "Our replica set config is invalid or we are not a member of it",
"code" : 93,
"codeName" : "InvalidReplicaSetConfig"
}
My configuration is:
> rs.config();
{
"_id" : "rs0",
"version" : 3,
"term" : 2,
"protocolVersion" : NumberLong(1),
"writeConcernMajorityJournalDefault" : true,
"members" : [
{
"_id" : 0,
"host" : "mongors-0.mongors-service.hes-all.svc:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "mongors-1.mongors-service.hes-all.svc:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("626fb63f211511c4dcf938ac")
}
}
configuration details seem right, but when I run rs.initiate, or rs.reconfig(cfg):
> rs.reconfig(config);
{
"topologyVersion" : {
"processId" : ObjectId("6347bdffe3c3303e6f325b9a"),
"counter" : NumberLong(1)
},
"ok" : 0,
"errmsg" : "New config is rejected :: caused by :: replSetReconfig should only be run on a writable PRIMARY. Current state REMOVED;",
"code" : 10107,
"codeName" : "NotWritablePrimary"
}
> rs.initiate();
{
"ok" : 0,
"errmsg" : "already initialized",
"code" : 23,
"codeName" : "AlreadyInitialized"
}
Any ideas?

Mongo Query Issue - Query records from two different collections and merge/join into one single record

I have two collections and From my queries , I got records from these collections as ,
Collection_A :
Query :
db.getCollection('Collection_A').findOne({"meta.md5":"270daaa8c9da2c0ce114fd297ecb3fce"},{"pdf":1,"_id":0})
Record :
{
"pdf" : {
"engine" : "pdf",
"status" : "done",
"retry" : 3,
"limit" : 4500,
"stop_on_detection" : 0,
"file_type" : "*",
"file_limit_slot" : 60,
"start_time" : 1543225534.08531,
"end_time" : 1543225534.90477,
"detection" : true
}
}
Collection_B:
Query :
db.getCollection('Collection_B').find({"md5":"270daaa8c9da2c0ce114fd297ecb3fce"},{"pdf":1,"_id":0})
Record :
{
"pdf" : {
"version" : {
"decomposer" : "1.0"
},
"results" : {
"status" : 1,
"vector_value" : 2,
"file_version" : "",
"is_portmanteau" : false,
"version" : {
"decomposer" : "1.0"
},
"pdfid" : {
"Encrypt" : 0,
"stream" : 2,
"JavaScript" : 1,
"OpenAction" : 1,
"JS" : 1,
"header" : "%PDF-1.1",
"entropy" : "",
"totalEntropy" : "",
"ObjStm" : 0,
"AcroForm" : 0,
"countEof" : "",
"xref" : 1,
"endobj" : 9,
"filename" : "270daaa8c9da2c0ce114fd297ecb3fce.pdf",
"version" : "0.2.1",
"AA" : 0,
"errorMessage" : "",
"Launch" : 0,
"RichMedia" : 0,
"endstream" : 2,
"nonStreamEntropy" : "",
"JBIG2Decode" : 0,
"trailer" : 1,
"isPdf" : "True",
"Page" : 1,
"countCharAfterLastEof" : "",
"dates" : {
"date" : []
},
"obj" : 9,
"EmbeddedFile" : 1,
"startxref" : 1,
"XFA" : 0,
"Colors" : 0,
"streamEntropy" : "",
"errorOccurred" : "False"
},
"file_id" : "ae9eb8ef543504666d2c4f58e1c2ff48",
"file_path" : "NA",
"pdf_id_error" : ""
},
"scan_duration" : 0.0714380741119385
}
}
How to merge these both records from these collections using a single query ? In SQL , I have used join to get data from two different tables. Since Im not familiar much with mongo , Not sure how to achieve this ?
Expected Result :
{
"pdf" : {
"status" : "Completed",
"detection" : true,
"pdf" : {
"version" : {
"decomposer" : "1.0"
},
"results" : {
"status" : 1,
"vector_value" : 2,
"file_version" : "",
"is_portmanteau" : false,
"version" : {
"decomposer" : "1.0"
},
"pdfid" : {
"Encrypt" : 0,
"stream" : 2,
"JavaScript" : 1,
"OpenAction" : 1,
"JS" : 1,
"header" : "%PDF-1.1",
"entropy" : "",
"totalEntropy" : "",
"ObjStm" : 0,
"AcroForm" : 0,
"countEof" : "",
"xref" : 1,
"endobj" : 9,
"filename" : "270daaa8c9da2c0ce114fd297ecb3fce.pdf",
"version" : "0.2.1",
"AA" : 0,
"errorMessage" : "",
"Launch" : 0,
"RichMedia" : 0,
"endstream" : 2,
"nonStreamEntropy" : "",
"JBIG2Decode" : 0,
"trailer" : 1,
"isPdf" : "True",
"Page" : 1,
"countCharAfterLastEof" : "",
"dates" : {
"date" : []
},
"obj" : 9,
"EmbeddedFile" : 1,
"startxref" : 1,
"XFA" : 0,
"Colors" : 0,
"streamEntropy" : "",
"errorOccurred" : "False"
},
"file_id" : "ae9eb8ef543504666d2c4f58e1c2ff48",
"file_path" : "NA",
"pdf_id_error" : ""
},
"scan_duration" : 0.0714380741119385
}
}
}
Update :
Tried This query :
db.getCollection('Collection_A').aggregate( [ { $match: {"meta.md5":"270daaa8c9da2c0ce114fd297ecb3fce"}}, { $lookup: {from: "Collection_B",localField: "meta.md5", foreignField: "md5", as: "pdf"}}, { $project: {"pdf.status":1,"pdf.detection":1,"_id":0}} ] )
But i'm getting this error from the robo mongo client
Failed to execute script.
Error:
Assert: command failed: {
"ok" : 0,
"errmsg" : "global.Collection_B cannot be sharded",
"code" : 28769,
"codeName" : "Location28769"
} : aggregate failed
_getErrorWithCode#src/mongo/shell/utils.js:25:13
doassert#src/mongo/shell/assert.js:16:14
assert.commandWorked#src/mongo/shell/assert.js:370:5
DBCollection.prototype.aggregate#src/mongo/shell/collection.js:1319:5
DBCollection.prototype.aggregate#:1:355
#(shell):1:1
Error: command failed: {
"ok" : 0,
"errmsg" : "global.Collection_B cannot be sharded",
"code" : 28769,
"codeName" : "Location28769"
} : aggregate failed :
_getErrorWithCode#src/mongo/shell/utils.js:25:13
doassert#src/mongo/shell/assert.js:16:14
assert.commandWorked#src/mongo/shell/assert.js:370:5
DBCollection.prototype.aggregate#src/mongo/shell/collection.js:1319:5
DBCollection.prototype.aggregate#:1:355
#(shell):1:1

mongodb who is primary in replication

How can I display which one is the primary mongodb machine from a Secondary replication, without being forced to login to every machine and check?
Running ismaster command only provide that current machine is secondary
rs0:SECONDARY> db.runCommand("ismaster")
{
"hosts" : [
"dbRby1:27017",
"dbRby2:27017",
"dbKrstd1:27017"
],
"setName" : "rs0",
"setVersion" : 5,
"ismaster" : false,
"secondary" : true,
"me" : "dbRby1:27017",
"maxBsonObjectSize" : 16777216,
"maxMessageSizeBytes" : 48000000,
"maxWriteBatchSize" : 1000,
"localTime" : ISODate("2016-11-24T07:36:09.855Z"),
"maxWireVersion" : 4,
"minWireVersion" : 0,
"ok" : 1
}
or by using the rc.conf(), I can't see that either
rs0:SECONDARY> rs.conf()
{
"_id" : "rs0",
"version" : 5,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "dbRby1:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 2,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "dbRby2:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "dbKrstd1:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : "majority",
"wtimeout" : 5000
},
"replicaSetId" : ObjectId("5811ec4c70c224f06fba884b")
}
}
rs.status() will give the wanted information as #Xenwar

insert documents in MongoDB multiple nested elements

I am looking to insert another document in a multiple nested document. Do you have any other ideas of how to solve it? Thanks
{
"_id" : ObjectId("576bddaa08b8f7dc20000033"),
"Name" : "Business",
"Image" : "fa fa-dollar",
"Description" : "Money, Capitalism, Business",
"NoForums" : 0,
"NoTopics" : 0,
"NoComments" : 0,
"NoUsers" : 0,
"CoverImage" : "https://www.rocklandtrust.com/assets/content/txh9vvwg/2014/08/06/business%20savings.jpg",
"Children" : [
{
"_id" : ObjectId("57715e0608b8f7441b00002d"),
"Name" : "Business School",
"URLName" : "Business-School",
"Image" : "http://www.small-business-website.net/wp-content/uploads/2016/04/How-to-achieve-a-successful-business-sale-128x128.jpg",
"Description" : "Everything about Business Schools",
"NoForums" : 0,
"NoTopics" : 0,
"NoComments" : 0,
"NoUsers" : 0,
"CoverImage" : "http://www.incae.edu/sites/default/files/styles/slideshow-un-medio/public/primerdiamba2010_018.jpg?itok=LfZmxw14",
"Children" : []
},
{
"_id" : ObjectId("57715f0d08b8f7942c00002b"),
"Name" : "Journals",
"URLName" : "Journals",
"Image" : "http://www.alliedacademies.org/images/accounting.png",
"Description" : "Journals and Diaries about Businesses",
"NoForums" : 0,
"NoTopics" : 0,
"NoComments" : 0,
"NoUsers" : 0,
"CoverImage" : "http://www.advantagebusinessvaluations.com/wp-content/uploads/2015/08/slide3.jpg",
"Children" : []
},
{
"_id" : ObjectId("57740ae208b8f7f41a000039"),
"Name" : "Stock Exchange",
"URLName" : "Stock-Exchange",
"Image" : "https://38.media.tumblr.com/avatar_bd29383b5657_128.png",
"Description" : "Stock Exchange, US Stock",
"NoForums" : 0,
"NoTopics" : 0,
"NoComments" : 0,
"NoUsers" : 0,
"CoverImage" : "http://c.fastcompany.net/multisite_files/coexist/imagecache/1280/poster/2013/04/1681873-poster-1280-stock-chart.jpg",
"Children" : [
{
"_id" : ObjectId("5774464608b8f7f41a00004a"),
"Name" : "Stock Software",
"URLName" : "Stock-Software",
"Image" : "http://s1.evcdn.com/images/block/I0-001/026/278/060-2.jpeg_/1-day-introduction-forex-stock-market-trading-60.jpeg",
"Description" : "Stock Excba ge Software",
"NoForums" : 0,
"NoTopics" : 0,
"NoComments" : 0,
"NoUsers" : 0,
"CoverImage" : "http://media.therakyatpost.com/wp-content/uploads/2015/04/stock-exchange-record-bigstock-900x470.jpg",
"Children" : []
},
{
"_id" : ObjectId("5774e2cb08b8f76c1a00002e"),
"Name" : "Meta Trader",
"URLName" : "Meta-Trader",
"Image" : "http://www.file-extensions.org/imgs/app-icon/128/6904/metatrader-icon.png",
"Description" : "MetaTrader",
"NoForums" : 0,
"NoTopics" : 0,
"NoComments" : 0,
"NoUsers" : 0,
"CoverImage" : "http://www.roboforex.com/files/filemanager/image/site/metatrader.png",
"Children" : []
},
{
"_id" : ObjectId("5774eb2708b8f76c1a000043"),
"Name" : "Meta Trader",
"URLName" : "Meta-Trader",
"Image" : "http://www.file-extensions.org/imgs/app-icon/128/6904/metatrader-icon.png",
"Description" : "MetaTrader",
"NoForums" : 0,
"NoTopics" : 0,
"NoComments" : 0,
"NoUsers" : 0,
"CoverImage" : "http://www.roboforex.com/files/filemanager/image/site/metatrader.png",
"Children" : []
},
{
"_id" : ObjectId("5774eb8208b8f76c1a000044"),
"Name" : "Meta Trader",
"URLName" : "Meta-Trader",
"Image" : "http://www.file-extensions.org/imgs/app-icon/128/6904/metatrader-icon.png",
"Description" : "MetaTrader",
"NoForums" : 0,
"NoTopics" : 0,
"NoComments" : 0,
"NoUsers" : 0,
"CoverImage" : "http://www.roboforex.com/files/filemanager/image/site/metatrader.png",
"Children" : []
},
{
"_id" : ObjectId("5774eb8f08b8f76c1a000045"),
"Name" : "Meta Trader",
"URLName" : "Meta-Trader",
"Image" : "http://www.file-extensions.org/imgs/app-icon/128/6904/metatrader-icon.png",
"Description" : "MetaTrader",
"NoForums" : 0,
"NoTopics" : 0,
"NoComments" : 0,
"NoUsers" : 0,
"CoverImage" : "http://www.roboforex.com/files/filemanager/image/site/metatrader.png",
"Children" : []
}
]
}
],
"URLName" : "Business"
}
How can I insert another document in Business.Children.Children.(Stock Software).Children
Use the positional operator to push values.
https://docs.mongodb.com/manual/reference/operator/update/positional/
db.collectioname.update(
{
"_id" : ObjectId("576bddaa08b8f7dc20000033"),
"Children._id" : ObjectId("57715e0608b8f7441b00002d")
},
{
$push: {
"Children.$.Children": {
"Name" : "Business School",
"URLName" : "Business-School",
"Image" : "http://www.small-business-website.net/wp-content/uploads/2016/04/How-to-achieve-a-successful-business-sale-128x128.jpg",
"Description" : "Everything about Business Schools",
"NoForums" : 0,
"NoTopics" : 0,
"NoComments" : 0,
"NoUsers" : 0
}
}
}
)
Note : Beware Mongo does not not allow nested documents to update.It is a known issue. It allows only to a single level.
https://jira.mongodb.org/browse/SERVER-831

Why Using GeohayStack fail

I run this query in mongo shell, and successful get result
db.tablebusiness.find({ "LongitudeLatitude" : { "$near" : [106.772835, -6.186753], "$maxDistance" : 0.053980478460939611 }, "indexContents" : { "$all" : [/^warung/] } }).limit(2);
I got:
{
"_id" : "warung-nasi-nur-karomah__-6.19_106.78",
"BuildingID" : null,
"Title" : "Warung Nasi Nur Karomah",
"InBuildingAddress" : null,
"Building" : null,
"Street" : "Jl. Arjuna Utara No.35",
"Districts" : [],
"City" : "Jakarta",
"Country" : "Indonesia",
"LongitudeLatitudeFromGoogle" : null,
"DistanceFromGoogleAddress" : 0.0,
"Checkin" : 0,
"Note" : null,
"PeopleCount" : 0,
"Prominent" : 45.5,
"CountViews" : 0,
"StreetAdditional" : null,
"LongitudeLatitude" : {
"Longitude" : 106.775693893433,
"Latitude" : -6.18759540055471
},
"Rating" : {
"Stars" : 0.0,
"Weight" : 0.0
},
"Reviews" : [],
"ZIP" : null,
"Tags" : ["Restaurant"],
"Phones" : ["081380087011"],
"Website" : null,
"Email" : null,
"Price" : null,
"openingHour" : null,
"Promotions" : [],
"SomethingWrong" : false,
"BizMenus" : [],
"Brochures" : [],
"Aliases" : [],
"indexContents" : ["restaura", "estauran", "staurant", "taurant", "aurant", "urant", "rant", "ant", "nt", "t", "warung", "arung", "rung", "ung", "ng", "g", "nasi", "asi", "si", "i", "nur", "ur", "r", "karomah", "aromah", "romah", "omah", "mah", "ah", "h"]
}
But when I try this query with additional search multikey index I got nothing result
db.runCommand({ geoSearch : "tablebusiness", near : [106.772835, -6.186753], maxDistance : 0.053980478460939611, search : { "indexContents" : { "$all" : [/^warung/] } }, limit : 30 })
I got this
{
"results" : [ ],
"stats" : {
"time" : 0,
"btreeMatches" : 0,
"n" : 0
},
"ok" : 1
}
This is index in my collection database
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "isikotacobacoba.tablebusiness",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"LongitudeLatitude" : "2d",
"Prominent" : -1,
"indexContents" : 1
},
"ns" : "isikotacobacoba.tablebusiness",
"name" : "LongLat_Prominent_indexContents",
"dropDups" : false,
"background" : false
},
{
"v" : 1,
"key" : {
"LongitudeLatitude" : "2d",
"Prominent" : -1
},
"ns" : "isikotacobacoba.tablebusiness",
"name" : "LongLat_Prominent",
"dropDups" : false,
"background" : false
},
{
"v" : 1,
"key" : {
"indexContents" : 1
},
"ns" : "isikotacobacoba.tablebusiness",
"name" : "indexContents",
"dropDups" : false,
"background" : false
},
{
"v" : 1,
"key" : {
"LongitudeLatitude" : "2d",
"indexContents" : 1,
"Prominent" : -1
},
"ns" : "isikotacobacoba.tablebusiness",
"name" : "LongitudeLatitude__indexContents_1_Prominent_-1",
"bits" : 22
},
{
"v" : 1,
"key" : {
"Title" : 1
},
"ns" : "isikotacobacoba.tablebusiness",
"name" : "Title",
"dropDups" : false,
"background" : false
},
{
"v" : 1,
"key" : {
"City" : 1
},
"ns" : "isikotacobacoba.tablebusiness",
"name" : "City",
"dropDups" : false,
"background" : false
},
{
"v" : 1,
"key" : {
"LongitudeLatitude" : "geoHaystack",
"indexContents" : 1
},
"ns" : "isikotacobacoba.tablebusiness",
"name" : "LongitudeLatitude__indexContents_1",
"bucketSize" : 0.1
}
]
How format use runCommand mongoDB using geohaystack with additional field mulikey??
Geohaystack queries do not support arrays for the additional field,
only single values. The current implementation of geospatial indexes
and geohaystacks do not use the standard query and index code.
The examples from MongoDB's geohaystack documentation (
http://www.mongodb.org/display/DOCS/Geospatial+Haystack+Indexing )
only shows the additional field to be a simple single value, not an
array of values in a geohaystack query.