Hot answers tagged

3

First of all, you can use a pipe mongodump -h sourceHost -d yourDatabase … | mongorestore -h targetHost -d yourDatabase … This reduces the time, as each document read will more or less instantly be restored on targetHost. However, this has the disadvantage that you might run into problems if the procedure is aborted for some reason, for example of a ...


2

You have a major mistake in your code. MongoClient creates a connection pool. Even in large applications, it is hence usually a singleton. So you should have it as a global variable, initialize it in main and reuse it in each runnable. Which is perfectly fine, since MongoClient is thread safe. Another thing to keep in mind is that although the single ...


2

I want to monitor accessNotInMemory of mongodb The database-level recordStats information was specific to the older MMAP storage engine and removed during the MongoDB 3.0 development cycle as part of the work toward collection-level locking and the new storage engine API. A more general performance indicator you can monitor is ...


2

In the context of MongoDB, a document means any piece of valid BSON* (binary JSON). The word does not have the everyday meaning of, say, an MS Word file or PDF. A collection is a container for zero or more documents. There is no requirement for all documents in a collection to have the same structure. Indeed, that is one of the drivers behind the NoSQL ...


2

By-and-large, you can't. Mongo offers atomic actions per document ie a single document will be successfully written or rolled back. There is no way (as of v3.2) to ensure a set of documents will be all written or all rolled back. Document self-consistentcy can be built into the JSON written. Coming from a relational point of view, think of it like a widely ...


2

You are mixing concepts here. Transactions are related to atomicity and guarantee that multiple operations are either executed as a whole or not at all. Consistency, however is (simplified) the guarantee that after each successful transaction or operation applied, the database is in a a valid, usable state. An example Note This example is simplified ...


2

You've seen the right behaviour since the default storage engine in 3.2 is WiredTiger(WT). The Wired Tiger provides up to 80% of the data compression to your data. Just to verify please note db stats before migrating and then after migrating the dbs to 3.2 to ensure you have got your data back.


2

Connecting to a replica set Most drivers will show the following behavior, as far as I know If only a single node is given, the driver will simply connect to this node. If the replicaSet option is given in the connection string, the driver will start to explore said replica set to identify all non-hidden members, regardless of the number of nodes given in ...


2

This depends on so much stuff. What are you building and how complex will your DB queries be? Hobby or professional use? Is the data critical? Do you need transaction safety? Do you already have all the data, in what format? or do you start from scratch? how many users do you expect? how many requests? Are you bound to PHP or can you use Node.JS? Is it a ...


2

Given your description I strongly suggest against using MongoDB. Not because it would necessarily a bad choice (although I believe it is in your case for reasons other than pure technical ones). Here are the points that caught my eye. Data modeling Trying to use MongoDB with relational data model with no adaptations almost always leads to tears and misery ...


2

Launch Shell as User If all else fails, on Ubuntu 14.04 LTS running on AWS, try this... ubuntu@foo $ sudo -u mongodb bash # OR whatever shell (zsh) mongodb@foo $ mongod --dbpath /data/db --fork OF COURSE, you'll add a much larger set of flags to the command. Invoke Command as User YMMV but this should work too... mongodb@foo $ sudo -u mongodb mongod ...


2

I deem that there are multiple (very important) aspects that you need to consider before deciding which tool you are going to employ to develop your project. The primary objective should be to manage the pertinent data as it is, a quite valuable organizational asset, and a reliable manner to achieve said objective is by way of technical means that are ...


1

If you know start _id and end _id then you can retrieve the bulk you inserted using query like this: db.yourCollection.find({_id:{$gt:ObjectId("56e13d5aed63a8477a7e2e78"), $lt: ObjectId("570f5a27b2d1a50996d3a0f0")}}) Replace the default mongodb ObjectIds with your _id fields. Also, if the _id you are using is default mongodb ObjectId then you can easily ...


1

You can find information about all users in all databases in system.users collection of admin database. See MongoDB documentation for system.users collection.


1

If you are running on Linux, you can use control groups to limit MongoDB memory as shown in the following article: Easy Steps to Limit Mongodb Memory Usage by Ramakanta Sahoo On Windows, a similar technique using the Windows System Resource Manager is described in: Limit MongoDB memory use on Windows without Virtualization by Simon Green


1

The valid and live members from replica set will automatically detect the arbiter which is in your replica set but not specified in connection. The driver will redirect the request to only Primary and secondaries knowing that arbiter will not serve any requests. It helps in voting in case of failover. However, its always good idea to add all members in ...


1

I have noticed the same thing in last week. Sometimes, the mongo shell returns any empty array: Try running the currentOp() many times to get the progress. Use use db command and then perform db.currentOp()


1

It is possible using cgroups. Some tutorials are available as well as shell script for Ubuntu 14.04. See also Is there any option to limit mongodb memory usage? on Stack Overflow.


1

Document in MongoDB is analogous to row in relational database. As opposed to relational database,MongoDB supports dynamic schema i.e documents can consist of varying fields. Collection is set of documents belonging to same entity similar to tables in relational database.


1

Typically, you don't. Thinking of your nodes in terms of primary or secondary is the wrong way to approach it. Since standard data bearing nodes should have the same dimensions, it is better to think of them as replica set members, one of which gets elected to primary. Since the drivers are replica set aware and know which the current primary is and you are ...


1

You can execute mongodump from the remote server as mentioned below: mongodump --host <ip-of-mongodb-server> --port <port-number-of-mongod> --out <some-directory> This is required mongo server to be accessible from the remote server. This dump file can be then compressed and archived on remote host or s3. If the mongo server is not ...


1

The problem is that MongoDB does not support file versions natively. So all we can do is to store the different versions and have some sort of metadata indicating the versions, then find the according file. Adding the complete metadata to fs.files (the wrong way) GridFS can store custom data in the metadata field of the files collection. > ...



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