Hot answers tagged

4

You need to add like this: let date = new Date().toISOString(); let isoDate = new Date(date); Hope it works.


4

The only real questions to mainly be considered when choosing between NoSQL and a Relational Database Management System (RDBMS) are: "Does the data have a well defined structure or is it very unstructured / variable in structure?" "Are the questions I need to ask of the data always simple?" And less important but valid: "Do I need ...


3

Replication is a risk mitigation strategy, amongst other purposes. If you understand those risks, and the consequences should they eventuate, and that's all acceptable in your context then by all means run multiple replicas on the same hardware. For a dev environment I can imagine this would be OK. A hardware failure would affect one person only. Recovery is ...


3

MongoDB doesn't have Data Definition Language. In place of "rows" and "columns" it has "objects" and "attributes". An object is typically not defined or constrained by the storage engine as it would be in a relational database. The data is not defined by the thing that keeps it but rather by the thing that reads and ...


3

After an unexpected crash, I can't restart ... the mongodb database Time to exercise your Recovery Strategy, put your Recovery Plan into operation and get your database back from the Backups you've taken of it. Your database is actually remarkably resilient. Left to its own devices (and all other things being equal) it will recover from a server crash all ...


3

The answer is no, the aggregation framework does not replace "every conceivable" MapReduce configuration. Without becoming a general purpose MapReduce framework with fully customizable functions, it can't. That's what you get with the existing MapReduce functionality - any functions you want (as long as they can be written in Javascripts of course)....


3

You can try this. db.testDBA.updateOne( {}, { $currentDate: { modifiedOn:true }, $set: { "item":"anything" } }) I inserted a new document and updated it. It worked. If I run this code again, the document will be updated like this


3

Just putting this here since I was struggling with the same for a while: Here is how you can do it in python3 Tested on mongo version 4.0 and pymongo version 3.11.4 import pymongo client = pymongo.MongoClient("mongodb://mongodb0.example.com:27017") admin_db = client.get_database("admin") milliseconds_running = 10000 query = [ {&...


3

Mongo -command have multiple parameters that are handy in this case. '--eval' let you run commands and '--quiet' keep all clutter away out=$(mongo --quiet --eval="db.currentOp()") ; echo $out


2

While the accepted answer is correct in that $group stage will not preserver order, I think it left some important information out and can be misleading. If you look at the comments on the Jira Ticket linked it clears it up there to. Basically it says that $group maintains the order within the 'groups' but order will not be guaranteed for stages after the ...


2

The MongoDB shell currently implements its own custom Map type, rather than the ECMAScript 6 Map type. Amongst the differences, the MongoDB type uses put instead of set to add elements to the map. This explains why you're seeing the "map.set is not a function" error. The three API functions on this custom map type are "get", "put&...


2

I performed a little benchmark, I uploaded 252 rows of data from an Excel into two collections testShortNames and testLongNames as follows: Long Names: { "_id": ObjectId("6007a81ea42c4818e5408e9c"), "countryNameMaster": "Andorra", "countryCapitalNameMaster": "Andorra la Vella", "...


2

The problem appeared after updating the binaries to version 4.2. When I start the mongo service, the service fails to start and the log shows this exception before it starts the shutdown procedure: 2020-08-07T14:58:26.205+0300 I STORAGE [initandlisten] exception in initAndListen: Location40415: BSON field 'MinValidDocument.oplogDeleteFromPoint' is an ...


2

To see your "real" chunk distribution count between shards, use command sh.status() at mongos. As you know, result should show that every shard have more or less same amount of chunks. Yes, you can disable the balancer and if you really use hashed sharding key, end result should be same as if you keep balancer running. Check that sh.status() ...


2

You could created a Replica Set with a Hidden Member. The hidden member will take a read/only copy of your data. However, if the hidden member goes down then the primary steps down to secondary, i.e. your MongoDB becomes read/only. You can define an Arbiter. It is not necessary to create the Arbiter service on a dedicated host, define it on your primary node....


2

Mongo database service doesn't search for answers to your query in only the cache. It searches in the memory and if it doesn't find your answers, it has to go into the storage. You can try the query below, and you will see the last data on your table. db.zips.find().sort({ "_id": -1 }).limit(10) Check out your data and your query, probably your ...


2

MongoDB has databases, collections and documents. These are analogous to databases, tables and rows in a SQL / tablular database. Then there are indexes and views which are similar to that of the SQL databases. You can inquire into an installation for these objects. Typically, using a client tool. The main client is the command-line mongo shell. You can ...


2

Turns out that I was missing a /authDBName in my connection string. It should be this: mongodb://myUser:userPW@SG-staging-111.servers.mongodirector.com:27017,SG-staging-43334.servers.mongodirector.com:27017/stagingDB?replicaSet=RS-staging-0&ssl=true&authSource=stagingDB


2

Should be this one: mongorestore --nsInclude="PetHotel.*" --nsFrom='PetHotel.*' --nsTo='PetHouse.*' dump/ mongorestore --nsInclude='*.*' --nsFrom='$database$.*' --nsTo='$database$2.*' dump/ First test it with option --dryRun See Change Collections' Namespaces during Restore


2

The simplest way to do what you’re asking would be to use a well-considered compound index. This article from MongoDB explains it pretty well: Compound indexes are indexes composed of several different fields. For example, instead of having one index on "Last name" and another on "First name", it is typically most efficient to create an ...


2

Generally, the order of query operators doesn't matter... But if you use $ne or $nin, it's better that those fields are part of a compound index and that index has (as a first field/fields) some selective field(s) AND of course, your query uses those fields. That way you select at first a smaller result set, from where it's faster scan thru the end result.


2

Unfortunately a multitude of the articles on this subject tend to generalize away the specific key facts that actually matter when making a decision on this matter, which has led to a lot of misinformation and confusion. First and foremost, there is nothing that makes a NoSQL database system faster when it comes to reading and writing data, no matter how ...


1

There is always possibility to use "OpLog tailing" where mongodb node is not part of replica set. It just replication changes of other MongoDB node/replica.


1

Turns out mongo cli client needs to be on version 4.4 I had version 3


1

For a secondary read preference, the server selection algorithm determines which node has the lowest round trip time, and randomly selects one of the nodes that is within 15 milliseconds of that latency. If the RNG is good, and the sample size large enough, that will usually balance, but not always. If you need to ensure strict balancing between the ...


1

That was a lot of questions for one question, but here goes: Is there any way to find out why MongoDB trigger moveChunk? The balancer will trigger a chunk move for a collection when the number of chunks on one shard exceeds the number of chunks on any other shard by the migration threshold Or any statistics for me to dig inside ? Each balancer run is ...


1

The replication coordinator mutex is used for nearly anything even tangentially related to replication. This is usually held for sub-microsecond periods when everything is running right. One possibility is the queries are taking the mutex in order to check the current status of the replica set member to make sure it is primary/secondary. If there is ...


1

The reason it is failing is right there in the logs: Data directory /data/db not found If you start mongod with no dbPath parameter it will default to /data/db. On your system, if you have used MongoDB in the past it must have been with a different dbPath or you have since deleted that path. I suggest you either specify a different path or create the /data/...


1

When MongoDB indexes an array, or a field in an array of subdocuments, the index is essentially a list of value -> recordId pairs. The value part is the actual field value, and does not include any information about the index of the value within the array. The query executor's index scan matches the queried value with the indexed values and returns a list ...


1

Interesting.. It should not be possible... From the source: cpp_name: oldOplogDeleteFromPoint  type: timestamp  optional: true # This field only exists on 3.4 upgrade  description: "The timestamp of the first oplog entry in a batch when we are writing  oplog entries to ...


Only top voted, non community-wiki answers of a minimum length are eligible