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

Call fsyncLock and fsyncUnlock non-consecutively using the same connection

From a bash backup script I want to call db.fsyncLock(), then execute other commands (fs snapshotting) and later db.fsyncUnlock() non-consecutively over the same connection, since it is advised as best practice. I tried named pipes, but mongo shell…
neurolabs
  • 542
  • 3
  • 8
1
vote
1 answer

can i have shard collection without index

i want shard a collection and this collection must have no any index (for fast insert operation). i create collection with autoIndexId : false and shard it, but when shard it, the mongo create index on shard key. Now, Can I have a shard collection…
Hamid Mamdoohi
  • 134
  • 1
  • 9
1
vote
1 answer

Declaration of variable unsuccessful in MongoDB shell

Here is my document: { $set: {"paths.0.pathBreak" : { "1": { "Key1" : [66.92, 22.34], "Key2" : "Val2", "Key3" : [64.92, 22.34], "Key4" :…
rahulserver
  • 10,411
  • 24
  • 90
  • 164
1
vote
1 answer

Update child element on mongodb

I've got a little problem with mongodb update method. This is my (simplified) schemas: { profile: { birthdate: "XXX", city: "xxx" }, account: { username: "...", password: "....", visits: 0 } } I've got 2000…
Metal3d
  • 2,905
  • 1
  • 23
  • 29
1
vote
1 answer

MongoDB Catch-22 won't let me drop huge collection

So I have a 2TB hard drive with 2 collections in 1 mongoDB. Collection 1 is about 500gb and completely essential Collection 2 is about 1500gb and needs to be deleted. I was running a process that accidentally filled up the entire HDD, leaving 0%…
LittleBobbyTables
  • 4,361
  • 9
  • 38
  • 67
1
vote
1 answer

Discrepancy between db.stats()/collections number & db.getCollectionNames() count

I am playing around in the mongodb-shell trying to learn about mongodb, and noticed that db.stats() shows number of collections to be 1 more than what is shown by db.getCollectionNames() Here is the example: > db.stats(); { "db" : "learn", …
Prakash Murthy
  • 12,923
  • 3
  • 46
  • 74
1
vote
1 answer

How can I change the type of objects' _id field to ObjectId in the MongoDB shell?

I have a few objects in a MongoDB database where the _id field was assigned an integer by mistake, how can I in the MongoDB shell replace these integers with an ObjectId? An example of such an object would look like this: { "_id" : 0 }
aknuds1
  • 65,625
  • 67
  • 195
  • 317
1
vote
1 answer

does MongoDB's getLastError() command indicate the number of records affected by a $rename command?

I'm developing an application that preens imported data using field maps in a "dictionary" collection, and am trying to see how many records were affected by a $rename operation. When does the mongo shell call db.getLastError() on behalf of the…
RubyTuesdayDONO
  • 2,350
  • 2
  • 25
  • 37
1
vote
1 answer

Query subset of fields based on count criteria in mongodb

My stored documents in a collection are in the format: { "a": { ... "b": { "c": cc, "d": dd, "e": ee, "f": ff } } } I…
1
vote
1 answer

Generate a new row, with a new GUID, from the MongoDB shell

I have some documents in a MongoDB collection with a GUID-type key, and I would like to be able to copy them to a new row, with a new GUID, using the shell. I tried this: db.schedules.find().forEach(function(x) { x._id = null; …
McGarnagle
  • 101,349
  • 31
  • 229
  • 260
0
votes
0 answers

"The term 'mongosh' is not recognized as the name of a cmdlet, function, script file, or operable program" error in vscode MongoDB shell

I tried to use mongodb shell from vscode via it's extension. Connection was stablished successfully but when I try to open mongobd shell I got this error. error screenshot : vscode terminal. I copied the path in env variable and was able to use…
helsinki
  • 1
  • 2
0
votes
1 answer

update config replication of mongodb sharded database access point mongos during run-time

I'm building a sharded MongoDB cluster, which I want to manage automatically. To achieve this I build the normal setup of a sharded db with: 3 replications of the config db 3 replications of shard "a" (initially only one but by growing the node…
0
votes
0 answers

mongodb is not distributing data evenly among shards

I have a database with 800k objects and I defined about 13 shard servers to access the data quickly. I assigned a letter to each object for use in the sharding process, for example, shards: 'a' for the first object, shards: 'b' for the second…
0
votes
0 answers

MongoDB $unset: "Executing this update would put you over your space quota"

I have a collection containing Reddit comments, gathered by a bot. The schema looks like this: { _id: ObjectId, author: string, body: string, permalink: string, created_utc: number, upvotes: number, downvotes: number } I…
0
votes
1 answer

Handling null values in MongoDB trigger function

I have a MongoDB instance configured in MongoDB Atlas. The instance contains two collections: Col_A Col_B When I update any object in Col_B, I have a MongoDB trigger which then uses the information in the Col_B changeEvent and updates part of what…
TheFlanman91
  • 141
  • 1
  • 2
  • 11