Using a BASH script to edit a Mongo database when there is no Mongo client installed - mongodb

I have an application running on a Raspberry Pi and it's storing data in a Mongo database, but the Mongo client is not also installed on the Pi. I'm using Alpine Linux for my OS.
I want to search for entries in the database using a single parameter in that entry (i.e. a filename) and then completely delete the entry from the database.
How can I accomplish this with a BASH script when the Mongo client is not installed on the Pi?
Please let me know.
Thanks!

The simple solution is install the mongo shell, or use one of the drivers such as pymongo.
If you're really good with bash, you might be able to use nc, telnet, or expect to connect to the mongod port, and speak Mongo Wire Protocol, which is not nearly as fun as it sounds.

Related

why is MongoDbB not running and not working?

i installed MongoDB compass and when i try to connect with hostname localhost ,Port: 27017
i receive this error: connect ECONNREFUSED 127.0.0.1:27017.
I also looked in Task manager and MongoDB was not running. Thank you for your help
MongoDB compass is only a client. you should install the mongo community edition (for development setup) and then use compass client to access it.
https://docs.mongodb.com/manual/installation/
MongoDB compass is graphical user interface (GUI) for the actual mongoDB. That is to say, you need an actual mongoDB running in order to be able to interact with the data through the GUI.
Once you have the database install, you can start it by typing the command mongo in the shell. There after you should be able to return to mongoDB compass and view the data in you database (I should mention, I'm assuming that you're running on the default port and on your local machine).

How do you convert mongod to mongo service?

I have been running MongoDB on two Windows 10 PCs. However, one has mongo always running it seems where I only need to open command prompt and type mongo. This gives me access to the db on PC #1.
However, on PC #2, I must open command prompt and type mongod. Then I have to open a second command prompt to type in mongo, then I get access to the db on PC #2.
After doing this for about a year, I find I want to just want both PCs to work like PC #1, where I just type in mongo and not mongodb and only have to use one command prompt.
I checked online but there's nothing I found straightforward to accomplish this specifically.
Does anybody know the answer?
If in PC#2, your MongoDB version is < 4.0, then you can't do anything i.e., you have to continue with mongod to start Mongo as you do now.
But if your MongoDB version is >= 4.0 or you want to upgrade from lower version of MongoDB, you can follow the below steps.
Take backup of all databases with mongodump. If it is large volume data, then go through this.
Uninstall your MongoDB using Windows Uninstall Program features.
Reinstall MongoDB using the link.
While installing, ensure you select 'MongoDB Service' feature.
Start the MongoDB now in PC#2 as you do in PC#1.
Restore the old databases with mongorestore.

Connect to Database directly via Mongo Compass

Via shell, I can directly connect to mongo database with this string
mongo --ssl host1,host2:port/MyDataBase...
And I land directly on the MyDataBase.
Is there a similar way to do it in Compass? I get connected to whole server and I can see all the other databases. I just want to connect to MyDataBase.
I am using the lattest version of Compass, so it may differ from your current version.
It is important the you are in the network of the server, or use a VPN connection, otherwise, it does not work.
Step 1
Step 2
Please,let me know if that works!

Mongodb community server on Windows 10: Can I access MongoDB shell command interpreter via ordinary telnet? (BEGINNER)

I am beginning to explore MongoDB and wish to write a small program/script using TCP socket to create a document in my local MongoDB community edition server. I would like to access MongoDB (which is now locally installed and running on my laptop) via a TCP socket.
I have installed MongoDB 4.2.3 community edition (with Compass.) As far as I can tell, it is running.
I can run mongo.exe shell:
C:\Program Files\MongoDB\Server\4.2\bin>mongo.exe
and the "show dbs" command yields what I would expect given that no documents or other data have been uploaded:
show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
Now, I would like to access mongodb via a TCP socket opened by my own (very small/simple) program so I can experiment with generating commands and observing responses (such as "show dbs").
When I telnet to localhost:27017 (using Windows 10 telnet client) telnet appears to connect to a socket (screen switches from "Connecting to localhost..." to a blank screen after a few seconds.)
As I am a beginner with MongoDB, I would appreciate a pointer as to how I can achieve my goal of using a small program I write to interact with MongoDB server.
Thank you, and I am happy to supply additional details as needed (and of course, would be grateful to a pointer to an example or other learning material that would help me proceed.)
Dave
MongoDB uses a custom wire protocol described here
If you are able to send binary values via telnet, you could probably make that work (I've no intention of trying)
You would probably find is simpler to use one of the pre-made drivers

In Meteor.js, how would I have two development projects use the same Mongo instance?

I would like to have two separate applications use the same Mongo DB instance, and since I am developing them at the same time I would like to be able to share the same development DB instance.
I realize that each instance of Meteor would have to run on it's own port. Is there a way to force meteor or mrt to connect to a local socket like the system version of MongoDB?
Yeah, you can just start meteor with the MONGO_URL parameter like:
$ MONGO_URL="mongodb://localhost:27017/myapp" meteor
or
$ MONGO_URL="mongodb://localhost:27017/myapp" meteor --port 4000
This assumes you have mongodb installed on your system. See this question for ways to make this process a little easier by using environment variables or a start script.
David's answer is in the right direction, but threw me off a little. Instead, we're doing this to start the first app as normal:
$ meteor
Then to start the second app and connect to the database of the first, we're doing:
$ MONGO_URL="mongodb://localhost:3001/meteor" meteor --port 3002
The key here is that meteor starts its own mongo instance on port 3001, and we can connect to that directly from a second meteor instance. David's answer uses your system's mongo for both apps.