Questions tagged [mongodb-shell]

The MongoDB shell is a command-line tool for querying and administering MongoDB.

The MongoDB shell is a command-line tool for MongoDB. It allows for querying collections, as well as admin functions like adding users, copying databases, and profiling.

Mongo Command Line

http://cheat.errtheblog.com/s/mongo

115 questions
3
votes
2 answers

Check if all elements in MongoDB array match a given query

Here's how my document looks: nookstore = { "name": "Nook store", "categories": ["bookstore"], "working_hours": [ {"opens": 8*60*60, "closes": 21*60*60 }, {"opens": 8*60*60, "closes": 21*60*60 }, {"opens":…
user1120144
3
votes
2 answers

MongoDB Shell: Error with "$or" query and explain()

I'm trying to do some profiling of a MongoDB "$or" query and I'm having trouble with the 'explain()' command in the Mongo shell. When I run my query with the find command, it works and returns one record, as expected. When I tack on an 'explain()'…
732
  • 661
  • 5
  • 12
2
votes
0 answers

Getting Error In MongoDB While restoring to Document DB "Unknown admin command atlasVersion"

I have taken the backup from Atlas mongodb,but the Atlas account was suspended. by using the backup i tried to restore it to aws documnentdb using the below command mongorestore --ssl \ --host=":27017" \ --username= \ …
2
votes
1 answer

mongodb shell login - password contains special characters like # and &

I am trying to login to mongodb database using mongodb shell, and if the password contains any special characters like # or & , the authentication fails. mongo mongo.cloud.com:8888/database -u username -p a7IF@WV^#66! mongo…
Mani
  • 1,471
  • 1
  • 13
  • 19
2
votes
0 answers

Mongo shell is showing as "Connecting..." . But not Starting the Shell

Im using MongoDB Community Server 4.0. I installed properly as said in the MongoDB Documentation. I have also set the path Environment variable for MongoDB bin. The windows service for MongoDB is also running properly. When I run MongoD with the…
2
votes
2 answers

In MongoShell: Not able to connect to my collection, db.collection_name return NaN

I am using MongoDB Enterprise, MongoDB shell version: 3.2.5 I have a db = mydb and a collections = ['events', 'events__2015-12-01', 'events__2015-11-01'] I have a python/pymongo script where I can connect to every document but in mongo shell I…
Crazyshezy
  • 1,530
  • 6
  • 27
  • 45
2
votes
1 answer

MongoDB: Custom command defined in .mongorc.js

I'd like to define a custom Mongo shell command. Given .mongorc.js is like below: var dbuc; (function () { dbuc = (function () { return db.getName().toUpperCase(); })(); })(); I'm getting proper upper-cased name for initial…
2
votes
1 answer

All data is getting stored into single shard only in MongoDB Sharded Cluster

I have created a MongoDB Auto Sharding Cluster having 3 Shard servers (without replication), 1 Config server and 1 Mongos instance. Here is the sh.status() output. mongos> sh.status() --- Sharding Status --- sharding version: { "_id" :…
2
votes
1 answer

How to update a mongodb string field from command line?

I am trying to update a field from command line (NOT from mongo shell) mongo mydb --eval "db.users.update({}, { $set : { email : "email@email.com" } })" results into Fri Oct 24 12:23:46.102 JavaScript execution failed: SyntaxError: Unexpected…
codeofnode
  • 18,169
  • 29
  • 85
  • 142
2
votes
1 answer

MongoDB: How to query a collection named "version"

I'm working with a mongo database that contains a collection named "version". Now it seems "db.version()" is by itself a reserved function and the collection name is hidden by it. Using the Mongo Java Driver it's possible to retrieve data from the…
user655145
2
votes
3 answers

Array output format in mongo shell

Is there a way to force the Mongo shell to output the contents of array sequentially across the page? Specifically: given an array [8888, 8888, 8888, 8888] I would like it to render as 8888, 8888, 8888, 8888 and not "r" : [ 8888, 8888, 8888, …
astebbing
  • 21
  • 3
2
votes
2 answers

Reassign MongoDB _id in shell

I'm trying to use the MongoDB to reassign IDs. However, it is not setting IDs equal to the value I assign, but rather it is creating a new ObjectId. How do I assign my own ID? > db.pGitHub.find(); { "_id" : ObjectId("516f202da1faf201daa15635"), …
Ben McCann
  • 18,548
  • 25
  • 83
  • 101
2
votes
1 answer

Trying to rename MongoDB document fields with spaces

I was a bit dumb and created a collection in MongoDB with spaces in the key names: { "_id" : ObjectId("5065f84d00ea10c01e00003f"), "DateTime" : ISODate("2012-09-27T15:19:00Z"), "Port Name" : "CL3-J", "Port Number" :…
Chris Matta
  • 3,263
  • 3
  • 35
  • 48
2
votes
1 answer

How to load mongodb script file while prompting for password?

I'm trying to connect to a MongoDB database that requires a password while also loading and running a script file on the database. I want to do it all from the command line and have the mongo shell exit afterwards. My problem is that I cannot do…
Thomas Watson
  • 6,507
  • 5
  • 33
  • 43
1
vote
0 answers

mongodb installation problem in ubuntu 22.04LTS

I am unable to complete installation process of mongodb in ubuntu 22.04 system using terminal by following steps Install the dependencies apt update apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common Download…