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

Mongo shell giving out the error "Multiple occurrences of option"

When using the following command mongo --username admin_user --password passw#ord^s --authenticationDatabase admin I get the error ""Error parsing command line: Multiple occurrences of option "--username". The version of Mongo shell 3.0.12. Can…
charitha
  • 361
  • 3
  • 9
3
votes
1 answer

mongodb server-side javascript is client-side actually?

I have a huge collection of documents and I want to extract some statistics on it. It needs to be executed periodically each 15 minutes. Most of the stats are based on the document size, so I need to fetch the documents and calculate its size. The…
richardtz
  • 4,993
  • 2
  • 27
  • 38
3
votes
1 answer

How to pull even numbers for an Array in MongoDB?

Let's say we have the following document: db.test.insert({a: [2, 3, 4, 5, 6, 7, 8]}) How to remove all even numbers and just left [3, 5, 7]? Can this be accomplished by using the $pull operator?
Just a learner
  • 26,690
  • 50
  • 155
  • 234
3
votes
1 answer

How to make comlex query MongoDB with Powershell

I need to retrieve data from mongoDB using Powershell. Let's say I have db.orders collection and need to retrieve only orders created during last week and retrieve only specific columns for instance _id, status, createdAt fields. Orders collection…
3
votes
1 answer

Get the inserted document(s) in MongoDB 3.0

Seems like db.collection.insert() used to accept a callback function as last argument but the api has since changed and now it just returns a writeResult object reporting only the number of documents inserted.. How can I get the actual documents…
ips
  • 111
  • 7
3
votes
2 answers

How to aggregate by floor in MongoDB

MongoDB Aggregation Framework doesn't have floor function. It only has simple arithmetic operators. So, how to compose floor function using them?
3
votes
3 answers

mongodb query on DBRef type

How do I turn this query in a valid mongodb Query in mongodb shell. { 'cars.owner.$ref' : 'users' } cars.owner is a DBRef here, but $ref is invalid I get this error: "$err" : "Positional operator does not match the query specifier." My objective…
Willem D'Haeseleer
  • 19,661
  • 9
  • 66
  • 99
3
votes
1 answer

How to efficiently aggregate several collections into one collection

I have four collections 1.links(movieId,imdbId,tmdbId) 2.movies(movieId,title,genres), 3.tags(userId,movieId,tag,timestamp), 4.ratings(userId,movieId,rating,timestamp). Now what i need to do is aggregate them into one collection as…
user2326210
3
votes
2 answers

MongoDB select all where field value in a query list

How to achieve below SQL in MongoShell? Select TableA.* from TableA where TableA.FieldB in (select TableB.FieldValue from TableB) Mongo doc gives some example of db.inventory.find( { qty: { $in: [ 5, 15 ] } } ) I want that array be dynamically…
HaBo
  • 13,999
  • 36
  • 114
  • 206
3
votes
1 answer

How to iterate through result object after querying in mongo DB shell

I am having a JSON array object something like [{_id:64,minitem:30},{},{}...] inside a variable result.. This is the result of an aggregation operation which is a projection of minimum score. I need to iterate over this result and delete the…
Prasanna Aarthi
  • 3,439
  • 4
  • 26
  • 48
3
votes
1 answer

Read image file into a MongoDB document's binary field via mongo shell script

I would like to read an image file into a MongoDB document's binary field from mongo shell. I can do this in Java with MongoDB Java driver. However, I would like to be able to do with a mongo script from mongo shell. Is this possible? For…
Roy Batty
  • 31
  • 1
  • 2
3
votes
3 answers

MongoDB toLowerCase()

I have a collection called Profiles, which contains an array called emails. I want to change all the email strings in the array to lowercase. db.Profiles.update({"emails":/@/i}, {$set: {"emails" : emails.toLowerCase()}}}) Error: Tue Jan 29 16:52:28…
Fruitful
  • 597
  • 2
  • 9
  • 16
3
votes
2 answers

MongoDB return all documents by field without duplicates?

Is there any way in the mongo shell I can return all documents in a collection, but order them by a specific field and remove any documents with fields the same as other documents? Thanks.
user775171
3
votes
1 answer

How can I use variables as part of field names in the MongoDB shell?

How can I use variables as part of field names in the mongodb shell? I am trying to do the following: > var site = "google.com"; > var y = 10; > var m = 5; // This fails (field names as concatenation): > db.test.update({ "domain" : site}, {…
OG Dude
  • 936
  • 2
  • 12
  • 22
3
votes
1 answer

Select specific database in mongorc.js

Is it possible to select a database that MongoDB should use on startup in the mongorc.js? use dbname is not functioning. This is a Non-JavaScript macro.
hellectronic
  • 1,390
  • 11
  • 15