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.

Most examples in the MongoDB Manual use the mongo shell; however, many drivers provide similar interfaces to MongoDB.

FAQ

713 questions
10
votes
4 answers

Connect to a specific database by default in mongodb

I am running a mongodb on a linux box. So every time I connect to it from the console (typing mongo) I get something like this: MongoDB shell version: 2.4.9 connecting to: test And then I am doing use myDatabase (where myDatabase is 99% is the…
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
9
votes
1 answer

How to mongo restore from atlas backup files?

I tried to restore mongo backup files from atlas. It's containing some wt files. How to restore. Backup downloaded from Daily Snapshots from atlas. Thanks in advance.
9
votes
3 answers

Install Only Mongo Client/Shell - not MongoDB on Windows

I found exactly same question for RHEL: (my question is for Windows) Install ONLY mongo shell, not mongodb Is there an Windows equivalent of: mongodb-org-shell Can I copy the mongo.exe from a Server installation on another Windows machine?
sumon c
  • 739
  • 2
  • 10
  • 18
9
votes
2 answers

Is the 'updateMany' function of mongodb deprecated?

db.movieDetails.updateMany({ "tomato.consensus": null, "imdb.votes":{$lt:10000}, "year":{$gte:2010,$lte:2013}}, { $unset:{"tomato.consensus":"" } }) When I typed the command above in the mongo shell, I received an error…
Syed Faizan
  • 901
  • 3
  • 14
  • 28
9
votes
2 answers

Get the size of all the documents in a query

Is there a way to get the size of all the documents that meets a certain query in the MongoDB shell? I'm creating a tool that will use mongodump (see here) with the query option to dump specific data on an external media device. However, I would…
Cydrick Trudel
  • 9,957
  • 8
  • 41
  • 63
9
votes
3 answers

How to "require(module)" in mongo shell

I am writing a mongo shell script for data management. I want to write it using modular code that makes use of function libraries as modules. In some cases, my own modules. In other cases, carefully selected node.js modules (that I know will work…
John Arrowwood
  • 2,370
  • 2
  • 21
  • 32
8
votes
1 answer

How to switch MongoDB database on the fly while using db.collection.insert()?

I have a multi-domain Rails 4 app where the request.domain of the http request determines which functionality I expose a given visitor to. Each domain in my app should be served by its own MongoDB database. E.g. domain1.com is served by…
Cjoerg
  • 1,271
  • 3
  • 21
  • 63
8
votes
1 answer

New Date and ISO Date conversion in Mongo shell

I was trying mongoExport with some date condition, I read here that date has to be in epoch format. Question is, I tried below, > new Date(2013,10,16) ISODate("2013-11-16T00:00:00Z") Assuming that I gave Oct-16-2013, But it returned me…
Srivatsa N
  • 2,291
  • 4
  • 21
  • 36
8
votes
1 answer

MongoDB Shell: find by BinData

I have a document in MongoDB like { "_id" : ObjectId("51723a2f2b9b90e9eb190c45"), "d" : BinData(0,"c9f0f895fb98ab9159f51fd0297e236d") } The field "d" is indexed, but how can I find by its value in mongo shell? e.g. db.test.find( {"d":…
Howard
  • 19,215
  • 35
  • 112
  • 184
8
votes
1 answer

extract subarray value in mongodb

MongoDB noob here... I have a collection as follows... > db.students.find({_id:22},{scores:[{type:'exam'}]}).pretty() { "_id" : 22, "scores" : [ { "type" : "exam", "score" :…
thefonso
  • 3,220
  • 6
  • 37
  • 54
7
votes
1 answer

Executing JavaScript function with mongo shell has no output

Here is my JavaScript function that I want to execute: var collectionCreation = function(){ db.myFirstCollection.find(); }; collectionCreation(); From my command prompt by pointing at bin directory I want to execute the js file containing above…
ManishChahal
  • 173
  • 1
  • 13
7
votes
2 answers

MongoDB type update from NumberLong to String

I've imported CSV file to my mongodb. CSV have separators as needed to mongo and was received from MySQL database with this query: SELECT * FROM csgo_users INTO OUTFILE 'b1.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';…
Grynets
  • 2,477
  • 1
  • 17
  • 41
7
votes
5 answers

MongoDB error: Cannot use 'commands' readMode, degrading to 'legacy' mode

So I was developing a project using mongo and I got an error after executing the code: db.usercollection.insert({ "username" : "testuser1", "email" : "testuser1@testdomain.com" }) The error displayed was: Cannot use 'commands' readMode, degrading to…
dgnebres
  • 165
  • 1
  • 1
  • 7
7
votes
1 answer

Mongo db shell variable printing only once

> var x = db.sampleDB.find(); > x output: { "_id" : ObjectId("55d02ed690ddbaafbfe20898"), "name" : "aditya", "city" : "meerut" } But if I print this variable again, it does not printing anything. and I am not able to print x.name? using ubuntu…
aditya
  • 149
  • 1
  • 3
  • 15
6
votes
1 answer

why does mongo trim spaces on save?

I'm noticing that MongoDB is collapsing multiple spaces together (into one space) when saving documents to a collection. It's not just leading and trailing spaces, but any sequence of spaces - and only spaces, not all whitespace (only tested with…
RubyTuesdayDONO
  • 2,350
  • 2
  • 25
  • 37
1 2
3
47 48