Questions tagged [mongo-shell]

The mongo shell is an interactive JavaScript shell for MongoDB, and is part of all MongoDB distributions. This section provides an introduction to the shell, and outlines key functions, operations, and use of the mongo shell.

Filter by
Sorted by
Tagged with
0 votes
0 answers
18 views

How can I change the default time zone in MongoDB using mongosh?

I'm working with MongoDB and using the mongosh shell. I'm trying to set a specific time zone for my MongoDB instance, but it seems like the usual approach using setParameter and the "timeZone&...
Roshan Gamage's user avatar
-1 votes
1 answer
42 views

MongoShell populate is not function?

i am working with MongoDB. i came across with an issue that i was trying to query data through MongoShell. but when i tried to run "populate" query from MongoShell, i gave error "....
Muhammad Afshal's user avatar
0 votes
0 answers
65 views

Setting a field in CosmosDB using MongoDB API by searching an external array of results from another database

Please note for the purposes of this question, I'm stuck on Mongo API v4.2. I've got a collection (validity) in one MongoDB database (AdminInfo) with an external ID reference field called ...
VitaminTussle's user avatar
0 votes
1 answer
29 views

Query for all keys having a particular value in a nested json document in mongodb

I am looking for a mongosh query to get all keys in a nested json that have values in a particular range or equal to a particular value. Consider the example json below { Root : { model_year :...
HelloUser2020's user avatar
0 votes
1 answer
82 views

How to import csv files into Mongo?

I want to import csv files into MongoDB. I found that there is a command "mongoimport" to import files. Based on mongoimport documentation I have installed the Database Tools for Windows: I ...
Paul Marcelin Bejan's user avatar
0 votes
1 answer
22 views

MongoShell works fine even though mongod is not active

When I enter the command systemctl status mongod I get: Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Mon 2023-09-25 ...
HRobertSI's user avatar
0 votes
0 answers
32 views

Understanding the output from the "findOne" query for mongosh cli (mongo shell)

I need to identify records that have both balance property (exists) and cat_id property set to a value. I basically want to check if such a record exists in the collection. I ran this first query: db....
George Udosen's user avatar
0 votes
0 answers
21 views

Mongosh can't execute use database in file

I'm using mongosh to execute commands for my MongoDB, and some of those commands would include changes of databases. So I need to execute commands like use db I'm trying to use directly a script and ...
Carabes's user avatar
  • 550
0 votes
0 answers
276 views

Openssl error in mongosh in amazon linux ami

I'm encountering an OpenSSL configuration error when attempting to use mongosh. The error message I receive is as follows: mongosh: OpenSSL configuration error: 00B927B69E7F0000:error:030000A9:digital ...
Madhu mohan's user avatar
0 votes
1 answer
21 views

Query in MongoDB to return documents matching at least two values in an array

Okay, I've been trying to wrap my head around this for a while and still cannot find the answer. Let's say I have a collection of Mongo documents containing a field with an array of strings called ...
fsesmajr's user avatar
0 votes
1 answer
95 views

user is not allowed to do action [collMod] on [db-name.collection-name]

I'm building an API with NodeJS, express and MongoDB. Before setting up post/put requests, I wanted to enforce a schema for the documents contained inside my collection and that's where the issue ...
Marco's user avatar
  • 3
0 votes
0 answers
29 views

Not able to Insert a record in Collection

I have been trying to validate the schema in MongoDB but encountering an error. I have tried Restarting the server, Dumping the collection, creating a new collection with the validation, created a new ...
Shrey Tandel's user avatar
0 votes
0 answers
35 views

How to install mongo legacy shell in MongoDB 6.0

The legacy mongo shell has been removed in MongoDB 6.0. Following the official Debian installation procedure for 6.0, it is not intalled (in favour of the new mongosh shell). However, due to some ...
fgalan's user avatar
  • 11.9k
0 votes
0 answers
20 views

Update field to correct subType

I have around 35.500 documents in my database. OfficeId field, is in this format: "OfficeId": { "$binary": { "base64": "bOKrjVPLTOCd5bYo6RYYOQ==", ...
DValdir Martins's user avatar
0 votes
2 answers
85 views

Using mongosh to create users and database automatically

Im currently using an armtemplate to create a Linux VM with MongoDB installed. Ive been using mongo script earlier for the version 4.4 of MongoDb. But we want to now start installing 6.0. In this ...
xatrivus's user avatar
0 votes
0 answers
26 views

mongo shell query of embedded documewnt

I have a collection built with embedded documents { "actions" : { "2089233" : [ { "task_name" : "...
Dror's user avatar
  • 5,175
0 votes
1 answer
29 views

How to add elements to array in mongodb document if exists empty array otherwise $set in updateMany?

So I have this object { name: "sunil" tags:null } { name: "radha" tags:[{k:"max",v:"4"},{k:"min",v:"3"}] } I want to update both these ...
Yashdeep Hinge's user avatar
0 votes
0 answers
62 views

How to improve the performance of $facet stage in Aggregation Pipeline in MongoDb

I had written a MongoDB aggregation pipeline in C#. I was able to obtain the correct result initially. However, after a couple of months, the dataset grew larger, and the aggregation started to ...
Shehan V's user avatar
  • 164
0 votes
1 answer
135 views

MongoDB run commands on a specific secondary node

I want to db.runCommand on a secondary node of a replica set, but not the primary (example). What connection string should I use in mongosh to connect to it? Connecting to the replica set (e.g. ...
C. Claudio's user avatar
2 votes
1 answer
64 views

How to get env from mongosh shell

I need to get an environment variable from mongosh. In the old mongo shell I could do it with the _getEnv method like this _getEnv("MONGO_INITDB_DATABASE"). That shell is removed from ...
Martin Kroll's user avatar
0 votes
1 answer
39 views

dockerfile - CMD mongoimport

FROM mongo COPY . /data/db2/ # Expose the MongoDB port EXPOSE 27017 CMD mongoimport --db test --collection data --file /data/db2/data.json The copy command copy data.json file when Im trying to put ...
aviv levari's user avatar
2 votes
0 answers
78 views

Stop Pretty default Mongo Shell (mongosh)

I jsut installed the new version, which is mongosh, and pretty printing is by default. When I am looking at multiple records, I find it inconvenient. Does anyone know how to turn off pretty print by ...
Adnan khan's user avatar
0 votes
0 answers
34 views

$where in Module: mongodb in npm not work correctly

I am newbie about mongodb. My application is using nodejs express and mongodb. I am using Module: mongodb in npm to connect and manipulate mongodb database from backend side. I insert the following ...
LeoPkm2-1's user avatar
0 votes
0 answers
13 views

mongosh toArray() is not a function

We are starting to work with mongo, and want to save the results of our queries to a file for reporting needs. I downloaded mongosh-1.10.1-win32-x64 and mongodb-windows-x86_64-6.0.8-signed set up a ...
frank's user avatar
  • 3,132
1 vote
0 answers
117 views

Issue Installing MongoDB 5.0.19: Missing mongo Binary on Ubuntu 20.04.6 LTS

I'm currently facing an issue while trying to install MongoDB 5.0.19 on my Ubuntu 20.04 system. After following the installation steps and confirming that the MongoDB service is up and running, I ...
Abhishek K V's user avatar
0 votes
1 answer
88 views

shardCollection command not working in mongosh

I am trying to shard my collection using mongosh, but its given error "no such command 'shardCollection' Are you connected to mongoose ? ". I am searched that error on google but i didnt ...
YAŞAR EMRE DOĞRU's user avatar
0 votes
1 answer
229 views

mongodb is not starting in mac M1

My mongodb was not working On my mac M1 so uninstalled and reinstalled from below link. https://www.mongodb.com/docs/v6.0/tutorial/install-mongodb-on-os-x/ still it is giving me below error. I tried ...
Kiran S youtube channel's user avatar
0 votes
0 answers
163 views

Error message when running mongoDB - connect ECONNREFUSED 127.0.0.1:27017

Running on MacOS Monterey I am receiving this message after trying to run the mongoshell mongosh Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&...
Jcurrr0's user avatar
0 votes
0 answers
62 views

Mongosh Aggregate: Access to variable ROOT disallowed

I am using aggregation in mongodb to group using multiple conditions, and want to return all field document not just the field that I used to group, thus I am using $$ROOT db.coll.aggregate([ { &...
Range's user avatar
  • 3
0 votes
1 answer
42 views

mongoose convert string to ObjectId by _MONGOSH in mongo compass

I want to do simple database update using _MONGOSH in Mongo Compass. I am putting this query, and getting error: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an ...
Karollo's user avatar
  • 45
0 votes
1 answer
130 views

Using UpdateMany to Add a New Field With The Value of Another Field as a String

I'm trying to add a new field to all of my documents that contains the value of a number field, but as a string instead (in an effort to do both a rename and a type change for that field). I tried ...
muttley91's user avatar
  • 12.3k
0 votes
0 answers
37 views

show collections and db.getCollectionNames() is displaying nothing but there is a collection present in the database

In my mongoDB compass there is a collection in database but show collections and db.getCollectionNames() in mongosh is not showing anything image of mongoDB compass image of mongosh I want the ...
user avatar
0 votes
2 answers
409 views

Mongosh doesn't connect to remote replica set but always tries on localhost

I have a weird issue while trying to connect to a remote Mongo replica set. This is my setup: on a remote machine I have three instances of MongoDB running on different ports, each belonging to the ...
zontar's user avatar
  • 485
1 vote
1 answer
83 views

MongoDB - DB Reference returns null value

As seen in this image when I try to retrieve address details from collection 'address_home' using DB Reference in MongoDB, it returns null value. Anybody know what is the problem with this code? I ...
VX7's user avatar
  • 23
0 votes
1 answer
25 views

upload geojson data to mongodb using mongosh

{ "type": "FeatureCollection", "name": "sql_statement", "crs": { "type": "name", "properties": { "name": "...
Muhammad Mursaleen's user avatar
0 votes
2 answers
63 views

Trying to select a single record from MongoDB using findOne searching for a value in a nested array

I've got a collection in MongoDB (6.0.2 community edition) called VS_Logs. In there is an array of objects looking a bit like this: Lookups: [ { REG: "ABC", .... // other stuff}, { REG: &...
Strontium_99's user avatar
  • 1,771
0 votes
0 answers
114 views

MongoDB on Mint

How to install MongoDB on Linux Mint 21? I have tried every tutorial available on the internet but it doesn't work can anyone explain step by step? The following packages have unmet dependencies: ...
Harikrishnan M's user avatar
0 votes
1 answer
36 views

How can I add each record to the sequence number in mongosh?

I use MongoDB 6.0. And I'm just trying to update each field with sequence number in mongosh. I want the field modified and update the collection. The sequence_number will be given from random number. ...
ThrowDevNull's user avatar
0 votes
0 answers
184 views

Disk space usage larger than expected (compared to Storage size)

I am currently working on a Software Project, where I’ve set up an M10 Dedicated cluster on MongoDB Atlas. The statistics of my database look like this: As it can be seen in the picture above, my ...
Vlad Nitu's user avatar
  • 147
0 votes
0 answers
36 views

Measuring the time it takes to manually insert data in MongoDB using mongosh - any tips?

Measuring the time of inserting data into mongoDB I'm using mongoDB Compass, but I'd like to enter the data manually through the built-in mongosh and measure its time. There is something like explain(&...
xjerc's user avatar
  • 1
0 votes
0 answers
222 views

Multiline copy paste not working in the MongoDB shell mongosh | Windows

I'm new to MongoDB, I was trying to use insertMany method and wanted to insert the below documents in a Collection. I copied from notepas++ but the Mongoshell gave the errors when I copy pasted. How ...
Coding_pundit09's user avatar
0 votes
0 answers
52 views

MongoServerError: Direct writes against config.transactions cannot be performed using a transaction or on a session

I try to delete mongodb database using bash script I got a mistake : MongoServerError: Direct writes against config.transactions cannot be performed using a transaction or on a session. But I excluded ...
Vera Odnoralova's user avatar
1 vote
0 answers
22 views

ObjectId() is being treated as a string literal instead of a function call in echo of bash script

I'm using a Mongo shell client to migrate some data in the database. But its ObjectId() is getting treated as string literal. mongo_command="db.getSiblingDB('${MONGO_DB}').${...
maq5ud's user avatar
  • 11
0 votes
0 answers
145 views

mongo shell: script print messages now shown

Here my script: use espaidoc; // List current indices of the "Audit" collection print("Current indices of the 'Audit' collection:"); db.Audit.getIndexes().forEach(index => ...
Jordi's user avatar
  • 21.4k
0 votes
0 answers
38 views

Mongo Shell query that looks for presence of a count of multiple conditions

I have a single, large document that represents applicationState. I want to build a Mongo Shell query that will tell me if more than one of several conditions is true. For example, let's say I have ...
Tim Hardy's user avatar
  • 1,653
0 votes
1 answer
170 views

How to work with legacy UUID in mongo shell?

I need to work with MongoDB databases that contain "legacy" UUID objects - BSON binData subtype 3 (created with pymongo). The MongoDB shell version v5.0.15 can work with both legacy and &...
Messa's user avatar
  • 24.5k
0 votes
1 answer
73 views

MongoDB - mongosh script - validation messages

I am running MongoDB (v 6.0.4) in docker. I have created a collection with a validation schema via a mongo script ( script file - test.js run with bellow command, the file is linked via volumes) ...
roivasot's user avatar
0 votes
0 answers
101 views

Running rs.status() throws BSONError: Invalid UTF-8 string in BSON document in mongosh

I have a simple replica set setup in a single computer with 3 instances. If all 3 instances are running i can check the status with rs.status() in mongosh, however, if I stop one of the instances, I ...
Hikaros's user avatar
  • 101
0 votes
1 answer
92 views

Aggregation $out stage creates collection, all queries return TypeError: db.collection.. is not a function

My goal is to create a materialized view using an aggregation on an existing collection. I was following this presentation - Materialized Pre-Aggregations for Exploratory Analytics Queries. There's an ...
abischolz's user avatar
1 vote
1 answer
36 views

Show storage engine config in mongosh

I've created a collection (in Java) with storage engine options where the block compressor should be zstd. How can I verify that .storageEngineOptions() worked as expected? Is it possible through ...
Jonas Byström's user avatar

1
2 3 4 5
15