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
0
votes
0 answers

Spring MongoDb template for shell commands

I am trying to create an application where I can pass the shell commands for mongoDB and then execute it in java. One of the exmaple I tried is as below DBObject dbobject=(DBObject) JSON.parse("{$and:[{sections.data.rowIdx: {$in:…
athenatechie
  • 699
  • 2
  • 8
  • 15
0
votes
0 answers

How to shoe log message on performing find query in mongodb using mongod shell?

I was reading this article of mongodb on Indexing and Performance . In this when they are performing any find query like db.names.find( {"name": "Arya"} ).sort( {"year": 1} ) They are showing some log messages which gives details about query. I dont…
0
votes
1 answer

Why mongodb connection url is not compatible for shell and driver?

I use this connection url to connect mongodb instance through driver: mongodb://localhost:27017?ssl=true and it works fine. But the same url doesn't work on mongo-shell instead I have to take out the ssl=true parameter and use mongo…
Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
0
votes
0 answers

mongodb shell not responding after running update query with $set

I am writing a query to find and update an array in a document, but mongo shell is not responding after running the update query using $set. The array in the document is not updated, and also no response is shown for any of the commands ran after…
Rajesh
  • 13
  • 3
0
votes
3 answers

Mongodb - delete docs from collection that do not have unique value

I have collection of objects such as this: {"_id":"...", "user":"foo", "value":"a"}, // this one stays coz its user is foo {"_id":"...", "user":"bar", "value":"a"}, // remove this one {"_id":"...", "user":"baz", "value":"a"}, // remove this…
Kunok
  • 8,089
  • 8
  • 48
  • 89
0
votes
1 answer

mongoDB shell - getting out of db.find() resultset

When you query something in mongo using db.collection.find() and if the result set exceeds the max allowed shellBatchSize, mongo prints n number of records and says type "it" for more. If oyu don;t want to see more, How to get out of this and get…
Vamsi
  • 52
  • 10
0
votes
0 answers

MongoDB: restore a collection in the mongo shell

I am trying to import/restore a single collection from within MongoDB (i.e. mongorestore cannot be accessed, I think ...?). Is it possible? What is the command? Ideally, I'd like to include indexes as well. The backup has been produced by…
Nico
  • 4,248
  • 1
  • 20
  • 19
0
votes
0 answers

MongoDb callback returns value undefined whereas Mongo shell returns the right results

I've a mongodb collection which has more than 20 million collection. db.collection.find({ 'attr.type': new RegExp('automotive snow' 'i') }).limit(10); Above mongo shell query returns the results as expected, But implementing the same in a node.js…
sachq
  • 672
  • 7
  • 11
0
votes
1 answer

mongoDB aggregate() finding email times in a collection of email objects

I'm new to mongoDB, the collection I'm working with was constructed by a python file that accesses my gmail using the gmail API.I'm trying to make a query to find the time of each day of the week with the highest number of received emails. Here was…
Hamon148
  • 137
  • 1
  • 12
0
votes
0 answers

Mongo Shell Is not Connecting when Using EBS volume for data

I am using EBS volume on my EC2 instance for storing data. And I installed and run mongodb successfully the only problem is that when I try to connect to mongo shell using sudo mongo admin --username root --password MY_ec2LOG_PASSWORD it give…
0
votes
1 answer

Mongo shell: how to display document's fields in lexicographic order?

This is what I get now: > db.collection_name.findOne() { "_id" : ObjectId("whatever") "c" : "a value" "a" : "a value" "b" : "a value" } Is there any function that I could use so that I can see the document's fields in lexicographic…
rwg05
  • 127
  • 6
0
votes
1 answer

Update nested array in MongoDB

I'm trying to do an update here in the mongo shell and I'm having trouble. I have the following json: { "_id" : ObjectId("56cc03c16f4e85f538ef79ae"), "contact_id" : NumberLong(1000295524418), "gender" : 1, "phonetic_gender" : 1, "first_name" :…
Jhonathan
  • 330
  • 1
  • 2
  • 14
0
votes
2 answers

Mongodb can't find object with too long _id

I have a little bit strange situation. I persist objects in collection "refs" explicitly setting _id. So I have objects with very big id's. db.refs.find().sort({_id: -1}); // {_id: 9200000000165761625} // ... But when I try to find object with…
corvax
  • 1,095
  • 1
  • 10
  • 35
0
votes
1 answer

Is this a bug in MongoDB Shell

I have two users, a user with root role and another user with read only role on the database. When I login as root then switch to read only user without exiting the shell, MongoDB allows me to run and execute root level commands even though I am…
fanbondi
  • 1,035
  • 5
  • 18
  • 37
0
votes
0 answers

Mongoose not returning a query resulting in documents >700 but mongo shell does

I have a user collection which has 1000 documents,when i call find() function using mongoose in node.js,it does not return any result or throw any error. But when i query through mongo shell it returns all results. Neither the docs nor the err is…
scionoftech
  • 608
  • 2
  • 9
  • 24