In MongoDB, you can create an index on a collection using the createIndex()
method, the createIndexes()
method, or the createIndexes
administration command.
Category: DBMS
Database Management Systems
Create a Wildcard Index in MongoDB
There are several ways to create an index in MongoDB, and from MongoDB 4.2, we can create wildcard indexes.
A wildcard index can be thought of as a kind of filter that automatically matches any field, sub-document or array in a collection and then indexes those matches.
Continue readingHow to Set the featureCompatibilityVersion in MongoDB
In MongoDB, the setFeatureCompatibilityVersion
command enables or disables the features that persist data incompatible with earlier versions of MongoDB.
How to View your featureCompatibilityVersion in MongoDB
The example on this page demonstrates how to view the featureCompatibilityVersion
for a mongod
instance.
How to Merge Documents when Importing a File into MongoDB
When you use mongoimport
to import files into MongoDB, you have the option of merging existing documents with the ones that you’re importing.
In this case, if an imported document has the same _id
value as an existing one in the collection that you’re importing into, the existing document will be merged with the one being imported.
You can also specify another field (other than the _id
field) to be the matching field if required.
How to Replace Existing Documents when Importing a File into MongoDB
When you use mongoimport
to import files into MongoDB, you have the option of replacing existing documents that match the ones you’re importing.
By this I mean, if an imported document has the same _id
value as an existing one in the collection you’re importing into, the existing document will be replaced with the one being imported.
You can also specify another field (other than the _id
field) to be the matching field if required.
The way to replace existing documents when using mongoimport
is to use upsert
mode.
Import a CSV File into MongoDB with mongoimport
When using MongoDB, you can use mongoimport
to import documents into a collection. mongoimport
is a command line utility that imports content from an Extended JSON, CSV, or TSV file. The import file could have been created by mongoexport
or some other export utility.
This article presents examples of importing a CSV file into MongoDB.
Continue readingImport a JSON File into MongoDB with mongoimport
When using MongoDB, you can use mongoimport
to import documents into a collection. mongoimport
is a command line utility that imports content from an Extended JSON, CSV, or TSV file. The import file could have been created by mongoexport
or some other export utility.
This article presents examples of importing a JSON file into MongoDB.
Continue readingThe Import Modes of mongoimport
When using mongoimport
to import files into MongoDB, you have the option of specifying a mode to use. These modes determine what happens if there’s already matching documents in the collection that you’re trying to import into.
By default, mongoimport
uses insert
mode, but there are other modes you can use. The mode you use will depend on what you’re trying to do.
Below is an overview of each mode along with examples.
Continue readingHow to Export MongoDB Query Results to a CSV File
The MongoDB Database Tools include a utility called mongoexport
that enables you to export MongoDB data to a CSV or JSON file.
One of the things you can do with this utitlity is export query results. This article shows you how to use mongoexport
to export MongoDB query results to a CSV file.