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

Mongodb filter embeded docs by parent field

I have the following structure in my mongodb: { "preferred_child": "child_id_2", "children": [ { "id": "child_id_1" }, { "id": "child_id_2" } ] } Using the mongo shell, how can I…
Liviu
  • 1,023
  • 2
  • 12
  • 33
0
votes
1 answer

String to date in MongoDB either shell or PyMongo

I'm very new to MongoDB and its queries but at the moment, I can't change a 'column' in a collection from string to date. My database and collection are both called thdr. I want to change the column 'PSTNG_DATE' to a date format. At the moment the…
Mark Wellings
  • 71
  • 1
  • 9
0
votes
1 answer

Aggregation using Project and Slice, mongodb

I've seen similar questions but far to complex for a newbie like myself. Plus none of the answers offered a syntax break down. My database: name :"Kim" points: [ { category:"Purchase", points: -50}, { category:…
0
votes
1 answer

Mongodb- using find() method on an Array of Objects only return first match instead of all

Unlike the other question someone asked where they wanted only one item returned. I HAVE one item returned and I need ALL of the matching objects in the array return. However the second object that matches my query is being completely ignored. This…
0
votes
1 answer

gets the total matching number of documents using mongo aggregate

I am trying to get the total number of matching documents on a set of fields using mongo aggregate. The aggregation query is like, db.results.aggregate([ {$group:{'_id':{name:'$name', id:'$id', date:'$date', amount:'$amount'},…
daiyue
  • 7,196
  • 25
  • 82
  • 149
0
votes
1 answer

MongoDB Index intersection example?

I am trying to understand why MongoDB fails to use Index intersection as mentioned over here. I have inserted 10000 documents in intersection collection using the below code block: for (var i = 0; i < 10; i++) { for (var j = 0; j < 10; j++) { …
Ashesh
  • 3,499
  • 1
  • 27
  • 44
0
votes
0 answers

How can we solve unexpected tocken error in mongo shell command?

In my test server I am using mongo shell version 2.6.10. When I run below command (it is for update datatype from string to float). I am getting an error SyntaxError: Unexpected token. In mongo shell version 3.4.4 it is working. var ops = []; …
Sarath TS
  • 2,432
  • 6
  • 32
  • 79
0
votes
1 answer

Insert data in mongodb using javascript loop

I want to insert data in a mongodb collection with a javascript loop. Here is my code : var collection = db.DATA.find(); for (var i = 0; i < 3; i++) { db.PARSED_DATA.insert(collection[i].folders); } I have the error…
Guillaume
  • 188
  • 1
  • 9
0
votes
1 answer

Error while installing mongo shell on macbook: Attempted to create a lock file on a read-only directory

I have been trying to install the mongo shell since two days but I am stuck on the same error which is been not solved on any of the posts. Have seen many tutorials regarding this but it wasn't fruitful. I hope someone could me to bring me back on…
0
votes
0 answers

comparing a string field to a sub-array field in mongodb

There are 2 collections with each containing details as below: Collection 1 (prpackages): {Server, Package, Version} Collection 2 (qapackages): {Server, Package, Version}. I need to get the package name from collection 1 and compare it against…
ncody
  • 1
  • 1
0
votes
1 answer

mongo shell same command across multiple collections

I am trying to do the following date conversion on multiple collections: db.u201409.find().snapshot().forEach( function (e) { e.sta = new Date(e.start); e.sto = new Date(e.stop); db.u201409.save(e); } ) As it can be seen, this is…
ffritz
  • 2,180
  • 1
  • 28
  • 64
0
votes
2 answers

Unable to connect to host on different system from mongo shell in windows

I am trying to connect to mongodb from my system to different system but i am getting following error- MongoDB shell version v3.4.5 connecting to: mongodb://192.168.0.152:27017/ 2017-06-23T18:06:50.643+0530 W NETWORK [thread1] Failed to connect to…
Praman
  • 19
  • 4
0
votes
0 answers

Using $sum to add up all the values of a two objects with arrays in Mongo shell?

I'm trying to get the sum of the second items in each array in each object. For ex: items: - 0 { "key": "Reservations", - "values": [date, amount], [date, amount], [date, amount] }, - 1 { "key":…
N. Sutton
  • 21
  • 3
0
votes
1 answer

Mongo shell insert statement for array of objects failing validation

I have the below collection schema which has been created and passed the validation: db.createCollection("Settings", { validator: { $or: [ {cID:{ $type: "int" } }, {sID : { $type: "int" } }, {default : [ …
S2S2
  • 8,322
  • 5
  • 37
  • 65
0
votes
0 answers

What does prototype mean in MongoDB shell?

when I input DB.prototype the mongodb shell said undefined But when i input DB.prototype.dropDatabase It return the source code of the method 'dropDatabase'. So,what the prototype means?So does DB?
lxacoder
  • 191
  • 1
  • 11