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

Convert a String to Object (json) MongoDB shell

I am trying to execute the below command function(field) { //field = '{"'+field+'":{$exists:true}}'; Not working //field = tojson(field) Not working //field = {"events.concessionDetails":{$exists:true}}; Works if passed as input param …
0
votes
1 answer

Console log in MongoDB Shell

I want to write functions into MongoDB Shell like this: var last = function(collection) { db[collection].find().sort({_id: -1}).limit(1).toArray(); } But there is one problem. When I call last() function, it will make no output. How to fix it?
Mike_Device
  • 634
  • 2
  • 8
  • 25
0
votes
2 answers

How to use the javascript var to reference the Mongo DB collection's field

I want to change the field value type from string to object. ...{value: "my title"}... ===> ...{value:{value:"my title ABC"}} In the Mongo shell, I present this field through the JavaScript var articlePath. Now, how can I use this var to update…
0
votes
0 answers

Mongodb db.currentOp(true) returns ReferenceError?

I was inspecting my mongodb performance by using db.currentOp(true), the mongo shell returned the following error message, but db.currentOp() works fine yqdmj:PRIMARY> db.currentOp(true) 2015-03-31T16:01:06.383+0800 ReferenceError:…
Jonathan
  • 33
  • 5
0
votes
0 answers

MongoDB Data-Modelling: a pattern for text search in referenced documents

I'm working on a project that use MongoDB; and I would like to hear your opinion about a feature I'd like to implement. In paticular there are "Users" that reside in "Cities" where they offer "Services". I have created three Collections…
0
votes
1 answer

How to change connectionsPerHost and threadsAllowedToBlockForConnectionMultiplier configuration in mongdb through mongo shell?

I need to change threadsAllowedToBlockForConnectionMultiplier and connectionsPerHost values in mongodb from their default value through mongo shell instead of a program. How can I go about it?
Siddharth
  • 2,046
  • 5
  • 26
  • 41
0
votes
1 answer

What javascript methods are available in mongo?

This is a general question and what i'm looking for here is a link to some resource. Explanation: I recently figured out how to run a mongo shell script (refer to this post: can't make basic mongo shell script with authentication) and in doing…
Dallas Caley
  • 5,367
  • 6
  • 40
  • 69
0
votes
1 answer

why shardCollection command not working in mongo shell script

i am trying to execute the following command within mongo shell script : sh.shardCollection('mydb.collection', { shardKey : 1 }); but it does not do anything. However When i execute from script : print(sh.help()) I get all the help options. So…
codeofnode
  • 18,169
  • 29
  • 85
  • 142
0
votes
2 answers

How could i query operation log(Oplog) in MongoDB?

I want to query the oplog to find what are the operation made in a particular time. How it possible to find and query oplog in MongoDB. Where oplog is placed? Please explain with an example...I could'nt find any tutorial over internet...
0
votes
1 answer

mongo eval not evaluating eval expression given through env variable

I'm trying to make a "wrapper" bash alias function to evaluate mongo snippets alias mongoshelleval=mongoshelleval mongoshelleval(){ mongo --verbose --eval $1 $db } And I have the snippets stored as env variables export…
laggingreflex
  • 32,948
  • 35
  • 141
  • 196
0
votes
2 answers

How to update document inside a document in MongoDB?

{ "_id" : O5, "bazar" : { "indiraBazar" : { "units" : "taka", "no" : 560, "value" : 0.90 }, "dhakaBazar" : { "no" : "no item", "value" : 1 }, "kolaBazar" : { "no" : "unlimited", …
Towhid
  • 1,920
  • 3
  • 36
  • 57
0
votes
2 answers

Connect to MongoDB with authorization

I have this below user created in MongoDB /* 1 */ { "_id" : ObjectId("5368247553e1d8650fdee0d1"), "user" : "userName", "pwd" : "3d8540469xxxxxxxxxxxxxxx28fbf8b76", "roles" : [ { "role" : "userAdminAnyDatabase", …
HaBo
  • 13,999
  • 36
  • 114
  • 206
0
votes
2 answers

mongodb foreach doc find min of subset and update it

Product and variants price Find Minimum of all products.Variants.Price where size is small and update it by 15% { "_id" : 23, "name" : "Polo Shirt", "Variants" : [ { "size" : "Large", …
HaBo
  • 13,999
  • 36
  • 114
  • 206
0
votes
1 answer

How to shutdown MongoDB Routing Server?

./mongos --configdb mongodb0.test.net:27030,mongodb1.test.net:27030,mongodb2.test.net:27030 --port 27040 --logpath routing.log --fork I run this script to setup my routing server. For mongod, I can use --shutdown or enter to mongo and write…
fmchan
  • 760
  • 1
  • 11
  • 29
0
votes
5 answers

Increment all array elements

I have a document like this: { "_id" : ObjectId("534527e489e46c16787bda0f"), "packages" : [ { number: 1 }, { number: 2 } ] } I want to increment all packages.number at once. Is it…
chaliasos
  • 9,659
  • 7
  • 50
  • 87