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
1
vote
1 answer

How to delete Duplicate objects inside array in multiple documents in mongodb?

I am trying to delete the duplicate object inside the array in multiple documents in Mongodb. I try many ways but not able to fix Document Structure:- { "_id" : ObjectId("5a544fe234602415114601d3"), "GstDetails" : [ { "_id" :…
1
vote
3 answers

How to start and stop mongodb server on windows?

To Start C:\Windows\System32>net start MongoDB The MongoDB service is starting. The MongoDB service was started successfully. To Stop C:\Windows\System32>net stop MongoDB The MongoDB service is stopping. The MongoDB service was stopped…
1
vote
0 answers

mongodb second replica set all are secondaries

I have created one replica set with the following commands mongod --replSet s0 --dbpath E:/mongo/data/shard0/rs0 --port 37017 --shardsvr mongod --replSet s0 --dbpath E:/mongo/data/shard0/rs1 --port 37018 --shardsvr mongod --replSet s0 --dbpath…
nithin
  • 371
  • 9
  • 24
1
vote
0 answers

How to specify the types of the mongodb shell types in a script file?

I'm writing some scripts for my mongodb, they should be run just with the server, to create users and other stuff. However, I find myself constantly moving between the editor and the mongodb documentation to know what does what. I'm using VSCode,…
Michael Jota
  • 138
  • 8
1
vote
2 answers

Document collection having '-' in name (e.g. internal-metrics) is not detected by db.collection.deleteMany() method

I have document collection in mongoDB database captioned 'internal-metrics'. I want to empty this collection to fill it with fresh data. I tried using db.collection.deleteMany() and db.collection.remove() methods but both responded with following…
1
vote
1 answer

How to find mongoDB object by ObjectID w/MongoDB Shell?

How can I do this in the MongoDB shell? https://stackoverflow.com/a/14315888/8887398 Basically I'm trying to find objects by their ObjectId. All are failing so I assume it's trying to compare to string. I'm doing this directly in the MongoDB shell.…
Birdman
  • 1,404
  • 5
  • 22
  • 49
1
vote
0 answers

How to open authenticated connection to Cosmos DB emulator with Mongodb shell?

When I run mongo --port 10255 --ssl I get a connection to Cosmos db emulator in Mongodb mode. When I in that shell try to run db.runCommand( { shardCollection: "myDB.myCollection", key: { myId: "hashed" } }) I get { "_t" :…
1
vote
2 answers

Docker Unable to connect to mongodb cloud

Unable to connect to mongodb cloud using mongoshell from Docker. Working on Opensuse 42.3 linux platform. IP_FORWARD has been enabled, firewall has been disabled. ./mongodbshell/bin/mongo "mongodb+srv://cluster0-ry2xn.mongodb.net/test"…
Magnus Melwin
  • 1,509
  • 1
  • 21
  • 32
1
vote
1 answer

MongoDB - String to ObjectID and create new collection

db.firmalar.find().forEach(function(obj) { for( var i = 0; i < obj.osgbIdleri.length; i++){ //ObjectId ARRAY obj.osgbIdleri[i] = ObjectId(obj.osgbIdleri[i]); } //out:result (firmaId.id & firmaId.osgbIdleri.id(ObjectId)) }); I…
Erdem Aydemir
  • 389
  • 1
  • 6
  • 26
1
vote
1 answer

Find and change all date type fields in mongodb collection

I have a collection with multiple date type fields. I know I can change them based on their key, but is there a way to find all fields that have date as a type and change all of them in one script? UPDATE Many thanks to chridam for helping me out.…
S0m30n3
  • 334
  • 2
  • 15
1
vote
1 answer

"..." in MongoDB Shell (version 3.2)

Currently running the following aggregate query in my mongo shell: db.zips.aggregate([{$group:{_id:{"state":"$state"},{population:{$sum: "$pop}}}]) and when I press enter, "..." shows up with a blinking cursor. Is it taking a long time to run or…
vince
  • 7,808
  • 3
  • 34
  • 41
1
vote
1 answer

MongoDB script execute queries stored in variable

My .js script reads from a file containing mongodb queries and populates it into an array. Then I read that array and executing the queries but they are not being executed. Below is my code. 1. //After successfuly connecting to mongodb 2. //read a…
fanbondi
  • 1,035
  • 5
  • 18
  • 37
1
vote
1 answer

Query MongoDB from Terminal on Spring Boot app using MongoDB

I have a Spring Boot app configured with default settings to use MongoDB. In order for my Spring Boot app to work, I have to manually launch MongoDB from terminal so I thought I could do commands from the shell to see what I was doing in the app.…
gohmer
  • 55
  • 1
  • 13
1
vote
1 answer

Unable to access MongoDB collection from shell when the name contains '-'

I have a collection named GoldenGlobes-emotion in my MongoDB 2.6.9 I found I can not access this collection from the MongoDB shell When ever I try to access the collection, for example db.GoldenGlobes-emotion.findOne() I always got…
Jim GB
  • 83
  • 1
  • 10
1
vote
2 answers

MongoDb shell simple find(): Why not authorized?

How is this even possible? What am I missing?... Edit 1: Ignore the db.posts.find vs. db.post.find typo above. I re-auth'd and tried the latter and get exact same denial. Am I dumb or do MongoDb permissions make no sense at all? Ok don't answer…
Locohost
  • 1,682
  • 5
  • 25
  • 38