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

How do I perform integer arithmetic in mongodb shell?

Is there any way to perform integer arithmetic on two NumberInt or NumberLongs in MongoDB's mapreduce Javascript or in the shell? As you see, I get: > typeof (NumberInt(1) + NumberInt(1)) number # (and this is here sort of just to gripe) >…
Scott Stafford
  • 43,764
  • 28
  • 129
  • 177
0
votes
1 answer

Error running mongod command in Linux

I am trying to run the command mongod --dbpath=data/db When I get this error: mongod --dbpath=data/db [initandlisten] MongoDB starting : pid=10161 port=27017 dbpath=data/db 64-bit host=anr [initandlisten] db version v2.4.9 …
vamsiampolu
  • 6,328
  • 19
  • 82
  • 183
0
votes
1 answer

Update MongoDB subdocument field using value of another field

Based on this SO question and actually this answer I try to update a field on a subdocument. My code is: db.venue.find().limit(10).forEach( function (elem) { for (var i = elem.events.length - 1; i >= 0; i--) { …
Diolor
  • 13,181
  • 30
  • 111
  • 179
0
votes
1 answer

How to deactivate safe mode in the mongo shell?

Short question is on the title: I work with my mongo Shell wich is in safe mode by default, and I want to gain better performance by deactivating this behaviour. Long Question for those willing to know the context: I am working on a huge set of data…
Aldian
  • 2,592
  • 2
  • 27
  • 39
0
votes
1 answer

Mongo shell, how to find/aggregate embedded documents with lists

I'm trying to aggregate/find data on subdocument that have lists of documents.... I have a mongo document that looks similar to this, {'town-name': 'anyplace ville', 'locations': { 'sports': [ {'name': 'football world', 'audience':…
user772401
  • 2,754
  • 3
  • 31
  • 50
0
votes
1 answer

connecting to remote mongo db server and running clone

I am migrating from server OLD at the old hosting company to server NEW at the new hosting company. I want to run the clone command so I clone the mongoDB from OLD to NEW. For OLD: The public ip address is: 44.55.66.77. The machine login user name…
Barka
  • 8,764
  • 15
  • 64
  • 91
0
votes
0 answers

National characters in mongo shell can not be used

my mongod instance is running on a server with Ubuntu 12.10 (x86_64). From the mongo shell I'm am not able to perform commands like this: db.listings.update({manName: "Schffer"}, {$set: {manName: "Schäffer"}}) The character 'ä' is not possible to…
martin
  • 13
  • 3
0
votes
1 answer

mongo shell: how can I return a date stored in ms formated in a readable form?

I have a mongoDB with dates stored as ms. when I query the DB with: > db.drives.find({deviceID:4},{driveDate:1}) I get { "_id" : ObjectId("52725be3a3d27f8c9eee4022"), "driveDate" : 1383226033496 } I want to display this date within the result in…
otmezger
  • 10,410
  • 21
  • 64
  • 90
0
votes
1 answer

Mongodb only use single core? All queries stuck when there is a long running $near query

There are 1 million geo-data in my database and 20% of them are [0,0] I run the simple query db.test.find({lc:{$near:[0,0]}}), which is extremely slow. It costs about 20~30 seconds because the data will be sorted with $near operation. The CPU usage…
Mark_H
  • 770
  • 1
  • 6
  • 19
0
votes
1 answer

mongo shell: return only 1 element of nested array

I have the following data on a mongodb: { "name" : "bla", "log" : [ { "A" : 1, "B" : 10 }, { "A" : 2, "B" : 20 } ] } I understand how to return all values…
otmezger
  • 10,410
  • 21
  • 64
  • 90
0
votes
1 answer

Unable to find value using variable as field name in find() method within Mongo Shell

I've executed the following command in mongo shell: db.perscoll.insert({CT:{English:{genre:[{name:varGenre}]}}}) Now, i want to find whether genre for 'English' exists in the collection or not using find(), which will return either 0(false) or…
Pratik Borkar
  • 475
  • 2
  • 7
  • 17
0
votes
2 answers

mongodb complex or/and query

So I have a collections which stores the start and end times for an event and I would like a user to be able to query for events by specifying "filter" start and end times. The query should return any events that intersect with the filter times. I…
mike
  • 3,339
  • 6
  • 30
  • 34
0
votes
0 answers

From mongoshell how to insert utc datetime and epoch values as utc datetimes into mongodb

Trying to do a proof of concept of loading sample tick data into mongo db and the tick archive data is generally in utc and epoch and need to load it as is and output as utc only not local datetimes. How to insert utc datetime and epoch in mongodb…
mpaul
  • 3
  • 4
0
votes
1 answer

How can I tell if a specific Mongo instance has active connections?

I'm upgrading a sharded cluster and want to turn one of three mongos instance off. I've guaranteed that new incoming connections will not take place because I disabled the box in my load balancer. However, I'm concerned there might be existing…
AmarettoSlim
  • 75
  • 2
  • 6
0
votes
1 answer

Removing Non-Collection Embedded Document via Mongo Shell

So I've got an application that uses a lot of embedded documents, which is fine. However I've noticed that some embedded documents aren't displayed when you show collections in Mongo shell. Normally this isn't an issue, but whilst dicking with…
AlbertEngelB
  • 16,016
  • 15
  • 66
  • 93