The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Hot answers tagged

46

Add --forceTableScan Example: mongodump --forceTableScan -d database_name -o target_directory http://aug2uag.blogspot.com/2018/08/mongoexport-unrecognized-field-snapshot.html


6

Nothing works for me but this. mongorestore --gzip --archive=/path/to/file.gz --db db_name


4

these indexes are existing in collection : db.products.createIndex({"origins_tags": 1,"sortkey": -1}, { background: true }) db.products.createIndex({"last_modified_t": -1}, { background: true }) The MongoDB query optimizer chooses the most efficient query plan based on the query shape (combination of query predicate, sort, and projection) and candidate ...


4

There is No electable secondaries because priority of secondary node is set to 0 (see rs.conf() in the original post. Thanks to Mani for his suggestion!). I updated priority (and votes) for lxc-mongodb-02 (_id = 2): cfg = rs.conf(); cfg.members[0].priority = 2; cfg.members[2].votes = 1; cfg.members[2].priority = 1; rs.reconfig(cfg); lxc-mongodb-02 is now ...


3

You can use an aggregation query to check for duplicates before trying to create a unique index. For example, if you want to create a unique index on fields a and b: Insert some test data: db.mycollection.insert([ {a: 123, b: 456}, {a: 123}, {a: 123, b: 456}, {c: 789 }, {d: 321 } ]) Find documents with duplicate values: db....


3

400K/day inserts = 5/second -- not very fast. Not a problem for MySQL. 1M/day = 12/sec -- still not a problem. Your two queries can be handled by INDEX(user_id, request_time, ip_address). Is that combination of columns "unique"? If so, make it the PRIMARY KEY; that will make the two queries even faster. If you get to the point of needing more speed, we ...


3

Two things. Use the tool you already know. This simplifies development, and reduces the desire to prematurely optimize. Fit your environment to the requirements. The hardware required to store 400,000 x 10 byte rows per day is vastly different from 400,000 x 10,000 byte rows. Define your requirements by mocking up some sample data in MySQL, along ...


3

I'm late to the party but encountered the same problem only recently on VM's with relatively small amount of RAM (4 GB RAM, 50 GB HD, 5 GB data). Our workaround is to use mongodump's option --forceTableScan and, if secondaries should be used, adding also --readPreference secondary. That sped up our dump by factor 10 to 30.


3

How to tell if a project needs NoSQL database solution? I think that SQL limits define it, if project needs bigger database or bigger fields than it needs NoSQL. Am I right? You are not right ;) Choosing NoSQL over a relational database has a lot more to do with business reasons like: do we have people on the team already familiar with NoSQL ...


2

This question is for Linux, but for fellow windows users who found their way here and want a windows solution... the problem is your Mongodb service is stopped. So do the following steps: 1) cntrl-alt-del and open your task manager 2) click on 'services' 3) scroll down to MongoDB 4) right click and hit 'start' (or 'restart') go back to ...


2

I also ran into same issue. But was able to resolve by completely removing mongo first sudo apt-get purge mongodb-org* Then performing following sudo apt update sudo apt install -y mongodb sudo systemctl status mongodb You can refer to following link for the same: https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-18-04


2

Ensure you're using mongoimport version 3.4 or higher, and use the --columnsHaveTypes parameter to tell the import what type each column is. See the MongoDB Reference Documentation for details. The following types can be specified: auto() binary(<arg>) boolean() date(<arg>) date_go(<arg>) date_ms(<arg>) date_oracle(<arg>) ...


2

Your conclusion is correct: internal optimisations or implementation details may alter the order of results depending on the stage. The $group stage is intentionally not order preserving, so you cannot rely on observational behaviour. As noted in discussion on SERVER-24799: $group aggregation command should maintain document order in the MongoDB issue ...


2

The output you are trying to capture is the default prompt for the mongo shell in interactive mode. As at MongoDB 4.0 there isn't a built-in helper to return replica set member status as a string, but you can derive the same status in JavaScript. For example, create the following as getstate.js: var mystate = 'UNKNOWN'; // Note: isMaster command ...


2

Mongo Mongo is a document store. It's not a great solution to model this in a document store. You need people to list days and times desks are available. I would want to use something that could model timestamp ranges, and with good support for transactions. I would use something like PostgreSQL.


2

That is because your mongodump script has an --archive flag. Then you have to use it when doing mongorestore.


2

If I stop the network interface (eth0) of the primary server to activate ReplicaSet, should the myState attribute of the secondary server change to 1? Since you only have two voting members in your replica set, the strict majority of voting members required to elect or maintain a primary (n/2 + 1) is 2. You should expect that if either member is ...


2

You could do an aggregation pipeline using the lookup operation, where you only need to specify the user ID. Would be something like this: var my_user_id = "1234"; db.getCollection('campaigns').aggregate([ { $lookup: { from: "user_activity", let: { campaign_id_var: "$campaign_id" }, pipeline: [ { $match: ...


2

mongoreplay is currently not included in the Windows installation packages (as at MongoDB 4.0). This tool uses the libpcap packet capture library which is available on most UNIX/Linux platforms but is not standard on Windows. There's a relevant feature request to watch/upvote in the MongoDB Jira issue tracker: TOOLS-1730: Release mongoreplay for windows. ...


2

MongoDB Enterprise and MongoDB Atlas both include auditing capability with options to to filter for audit events including schema (DDL) changes, CRUD operations, authentication & authorization, and replication/sharding commands. Auditing was first included in MongoDB Enterprise 2.6 (March, 2014).


2

Both of the described approaches are very suboptimal in theory. My strong recommendation would be to design a more efficient schema to suit your data access & update patterns. For example, order items could be referenced in a separate collection rather than being embedded in an array. If you are currently using a single order document to ensure atomic ...


2

Monotonic here is used in the strict mathematical sense. A monotonically changing key is such that every key value is not less than (monotonically increasing) or not greater than (monotonically decreasing) all previously generated keys. A sequence, in the SQL sense of this word, would be an example of a monotonic key. A non-monotonically changing key, ...


2

I have trouble understanding this because even though the index is used for sorting , shouldn't it have done a collection scan to fetch the documents that needed to be sorted? If you fully iterate both of your queries they will end up fetching all documents from the collection, but they take different approaches in terms of query planning and execution. A ...


2

The different approaches for configuring setParameter options (via runtime admin command, config file setting, or command-line option) are listed in the Synopsis section at the top of the MongoDB Server Parameters page you referenced. You can use setParameter key/value pairs in the YAML configuration file. For example: setParameter: ...


2

Does pure MongoDB use schemas and models like Mongoose ODM? No, the MongoDB server (as at 4.0) does not have a concept of models or data relationships. Data is persisted in Documents which are stored on the server in a binary JSON-like serialization format called BSON. Does pure MongoDB have any validators? The MongoDB server does support per-...


2

I understand correctly, secondary index leaf nodes in MySQL InnoDB engine hold the table primary key value (at least for a unique index). InnoDB tables have a clustered index which determines where data for rows is stored. The clustered index for an InnoDB table is either the PRIMARY KEY (if set), the first unique index with all key columns NOT NULL, or ...


2

Can I choose which databases/collections are replicated ? A replica set is a group of mongodb instances that maintain the same data set, so it is necessary for the entire set of data to be replicated between nodes. Is a 2-members (a primary and a secondary) replica set eligible ? A replica set should have an odd number of voting members. If you want ...


2

For the people who will come here in the future the issue was, I was using MongoDB 4.0 on the local and server was on 4.2: Starting in version 4.2, mongodump uses Extended JSON v2.0 (Canonical) format for the metadata files. To parse these files for restore, use mongorestore version 4.2+ that supports Extended JSON v2.0 (Canonical or Relaxed mode) format. ...


1

We are accessing mongo using Java application and we are seeing that a lot of our queries are taking considerable amount of time such as 2-4 seconds. The provided output indicates a query that requires a collection scan of 2,209,900 documents to update a single document: "nscanned" : 0, "nscannedObjects" : 2209900, "nMatched" : 1, "nModified" : 1, we ...


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