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
28
votes
2 answers

Mongodb: Perform a Date range query from the ObjectId in the mongo shell

I have a collection that looks like this: { _id: ObjectId("50a68673476427844b000001"), other fields } I want to do a range query to find records between two dates. I know that I can get the date from the ObjectId in the mongo shell var doing…
sc28
  • 455
  • 1
  • 6
  • 8
20
votes
2 answers

TypeError occurs when trying to enable Mongo DB authentication

I'm on step 3 of trying to enable Mongo DB authentication. When I try to create a user via the Mongo shell exactly as the directions indicate, the shell reports: TypeError: Property 'createUser' of object admin is not a function I started mongod…
dingalla
  • 1,219
  • 3
  • 12
  • 19
20
votes
1 answer

MongoDB $or query

I run following query in mongo shell: db.Profiles.find ( { $or : [ { "name" : "gary" }, {"name":"rob} ] } ) It just returns nothing as expected(JSON)?
Fruitful
  • 597
  • 2
  • 9
  • 16
17
votes
2 answers

MongoDB $lookup not using index

I'm writing a query that requires a $lookup between two tables and as I understand it, it's essential that the foreignField have an index in order to perform this join in a timely fashion. However, even after adding an index on the field, the query…
ashe540
  • 2,041
  • 2
  • 17
  • 17
14
votes
3 answers

How to paginate output inside mongo shell

Is it possible to pipe results in to a pager from within a mongo shell? The mysql cli equivalent would be: mysql> pager less
davidmh
  • 1,368
  • 13
  • 24
13
votes
1 answer

How to find if Mongodb is running in auth mode in shell script?

I am having a mongodb instance running which is running auth mode in my server machine. Currently I am using a shell scipt to get whether there is a mongodb instance running or not. How Can I check whether if the mongodb is running in a auth mode…
Jeevitha G
  • 1,194
  • 3
  • 13
  • 20
9
votes
2 answers

mongodb debugging - ReferenceError: console is not defined

I got js file to run within mongodb where I got console.log expression for debugging: use test; db.city.find().snapshot().forEach(function(city){ var Pos = city.Pos; if (Pos) { longLat = Pos.split(" "); …
Maxim Yefremov
  • 13,671
  • 27
  • 117
  • 166
6
votes
3 answers

Get the current script path from MongoDB shell

I'm writing JavaScript code for MongoDB shell in client. How can I get the path of the script file which is executing? Please note it's not the value of pwd(). For example, I'm executing /my_scripts/utils.js from /my_path: > mongodb --nodb…
Jeffrey Zhao
  • 4,923
  • 4
  • 30
  • 52
6
votes
2 answers

MongoDB 2.4 Replica set with authorization

How to set up proper authorization for mongodb 2.4.1. My setup seem to be not working. Replica members config: dbpath = /vol/data/mongodb/ # logfile logpath = /var/log/mongodb/mongodb.log logappend = true # socket bind_ip = 0.0.0.0 port =…
Szymon Karnecki
  • 61
  • 1
  • 1
  • 3
5
votes
1 answer

Promises or async/await in mongosh?

I have a mongosh script that should execute things synchronously. Can I use promises or async/await in mongosh? It seems like I can't. Is there a way to ensure things don't get executed out of order? For example (1)…
cierech
  • 383
  • 4
  • 14
4
votes
1 answer

AWS DocumentDB through Proxy

I have an AWS DocumentDB set up that I can connect to just fine through my jump box using: mongo --ssl --host aws-host:27017 --sslCAFile rds-combined-ca-bundle.pem --username my_user --password I'd like to be able to connect to…
el n00b
  • 1,957
  • 7
  • 37
  • 64
4
votes
1 answer

Configure Mongo shell to store all numbers as integers by default

By default, the MongoDB shell interprets all numbers as floats; this is a problem when trying to convert existing JSON formatted data (stored as strings in Mongo) to actual Mongo BSON objects. It would also be tedious to explicitly and manually wrap…
Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111
4
votes
2 answers

How do you do an AND query on an array in mongodb?

I have an array with tags which is part of a document, eg ["red", "green", "blue", "white", "black"] Now I want to find all documents, which have red AND blue.
Piotr Zolnierek
  • 1,030
  • 1
  • 10
  • 19
4
votes
1 answer

How to use closures in mongodb shell?

I'm kind of confused on how to use closures in mongodb shell. I want to create a function that i can use exclusively during development to quickly look up a document by a part of it's _id. The function should return a $where selector that does the…
Willem D'Haeseleer
  • 19,661
  • 9
  • 66
  • 99
3
votes
2 answers

how to match both fields are not exist

I was trying to use $and to express both fields are empty Here is the code db.tweets_v2.aggregate({ {match:{$and:[{replyto_id:$exist:false},{replyto_id:$exist:false}]} });
Jay Park
  • 308
  • 1
  • 6
  • 14
1
2 3 4 5 6 7 8