Hot answers tagged

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

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


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

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

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 ...


3

Answer is priority... Higher priority wins. So, "host" : "10.0.0.2:27017", with "priority" : 5 wins the election against "host" : "10.0.0.5:27017", "priority" : 1. Solution is give priority 5 to node 10.0.0.5 and priority 1 to that 10.0.0.2


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

Using a read concern of "majority" does not cause the read operation to be submitted to multiple nodes. When replication.enableMajorityReadConcern is true (default in MongoDB 3.6+) each node will note the most recent write operation that has been acknowledged by a majority of the voting nodes, and keep a snapshot of the data at that point in time. ...


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

Delete the collection from the DB and then hit he API , it will work. There is no mistake in code.


2

There is no access control enabled with MongoDB by default, so this is something you'll need to configure separately. Fortunately, it's not too difficult thanks to the well-written MongoDB Manual. Here is the gist: Start MongoDB without access control (which I believe you've already done) Connect to the instance (which you've stated you've already done) ...


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

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

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 ...


2

A one-liner would be this one: mongo "mongodb://username:password@localhost:27018/admin?authSource=admin" --quiet --norc --eval "rs.status().members.filter( x => x.name == db.hello().me ).shift().health" Function db.hello().me returns the server+port you are currently connected to. Replace this expression if you like to query other ...


2

Excerpt from - https://docs.mongodb.com/database-tools/ Starting with MongoDB 4.4, the MongoDB Database Tools are now released separately from the MongoDB Server and use their own versioning, with an initial version of 100.0.0. Previously, these tools were released alongside the MongoDB Server and used matching versioning. Here's the link to download - ...


2

Schema Validation You can specify Schema Validation on the document's within a collection to validate the kind of data types you can insert or update for each field. In addition, you can also set other constraints like a required field. This feature will allow you maintain a specific data type for a field. Note that Schema Validation is optional. Field ...


2

You must increase the size of your primary node's oppLog size. Here you can find how! Problem is that there is not enough information stored "what happened" (changes to the collections) during that initial sync.


2

It is best practise to run as little as possible as root, or any other account with significant privileges. Each application or service should run with the lowest privilege set that will allow it to operate correctly, then if there is a problem (security bug in the service itself, security bug in the application software that uses the service, ...


2

Most goals are accomplishable in either type of database system, but you'll likely find more flexibility in how you can query the data (inclusive of modifying data) with a relational database, at the tradeoff (in your case) of having to convert from JSON into a normalized form. I think for maintaining data between two objects (operator_records and ...


1

You can filter the array using the $elemMatch projection operator (this is different from the $elemMatch query operator). db.collection.find( { }, { dammfield: { $elemMatch: { "f7.ff1": "123123123" } } } ) You can also use the aggregate operator $filter with the same result.


1

You can try this one: for (let d of db.adminCommand( { listDatabases: 1 } ).databases ) { db.getSiblingDB(d.name).getUsers() } This is javascript code in mongo shell, should be no big issue to convert it into python.


1

If DB system is designed (and build) to handle that load of X inserts per second, it won't impose abnormal strain on physical hardware. Hardware is built to handle it. When you are building your MongoDB, remember that MongoDB likes memory over CPU-power (ie. More memory makes Mongo faster than more CPU) and a fast disk (higher IOPS) is always better than a ...


1

That ",{Nombre:1, Apellidos:2}" part is 'projection', where you tell what fields you want to be in the result. Without it, all fields are included to result. Normally you use 0 to remove field 1 to include a field But, any positive value will work as "include field". This example find will return fields _id, Nombre, Apellidos Field _id ...


1

Yes, easily! Set priority of node 1 to higher than 1... Node 1 = 10.1.0.1 (Primary) - priority 2 Node 2 = 10.1.0.2 (Secondary) - priority 1 Node 3 = 10.1.0.3 (Secondary) - priority 0.5


1

The main factor here is the Replica Set Elections. Replica sets use elections to determine which set member will become primary. Replica sets can trigger an election in response to a variety of events, such as: Adding a new node to the replica set, Initiating a replica set, Performing replica set maintenance using methods such as rs.stepDown() or rs....


1

Starting with question 2: I have found no clear answer, but it is now obvious to me that fs snapshots is not sufficient for MongoDB version 4.0.19. We'll upgrade MongoDB if we can and will start using mongodump in addition to the fs snapshots. We'll probably stop MongDB before snapshots are made. At this point I do not know how corrupt files goes undetected ...


1

Yes, hot snapshot is easy and fast way to do backup... But of course there is also mongodump. Here is my crontab entry. Every hour, overriding current date backup. SHELL=/bin/bash DATEVAR=date +%d 31 * * * * /usr/bin/mongodump --host localhost -o /dbdata/dump$($DATEVAR) --gzip --oplog >> /dev/null 2>&1


1

Yes, it is not a good idea to use a dynamic (changing value) like an ObjectId as a field name. To query a specific bookmark you are looking for a specific value for a specific field. And also, to index bookmarks fields it is not possible as the field names are changing. You can use something like this, for the bookmarks field: bookmarks: [ { post_id: &...


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