如何远程连接到位于 K8S 之上的 mongo DB
目前我正在执行一项任务,将一些数据填充到 mongo DB 中。该 mongo DB 构建在 K8S 之上,如下所示。这是我第一次在这样的环境下工作。
,在“Shell”级别,我能够
mongo -u root -p
手动进入 mongo 控制台页面,并手动处理其余的数据库查询。
但我的问题是,在相同的“Shell”级别,我可以将所有查询包装在 JS 文件中并使用远程数据库连接字符串来执行它吗?
这是我尝试过的 read.js 文件的示例:
var db = connect('127.0.0.1:27017/fext'),
allDevices = null;
allDevices = db.names.find();
//iterate the names collection and output each document
while (allDevices.hasNext()) {
printjson(allDevices.next());
}
当我在此命令中执行它时:
mongo read.js -u root -p
评论?感谢您的帮助!
杰克
Currently I am working on a task to populate some data into a mongo DB. This mongo DB is built on top of K8S as follows. This is the first time I am working in such environment.
As you can see, on the "Shell" level, I was able to run
mongo -u root -p
to manually get into the mongo console page, and manually worked on the rest of DB queries.
But my question is, at the same "Shell" level, can I have all queries wrapped in a JS file and with a remote DB connection string to have it executed ?
Here is a sample of my read.js file I have tried:
var db = connect('127.0.0.1:27017/fext'),
allDevices = null;
allDevices = db.names.find();
//iterate the names collection and output each document
while (allDevices.hasNext()) {
printjson(allDevices.next());
}
And when I was to have it executed in this command:
mongo read.js -u root -p
I have got following returning message:
Comments ? Thanks for the help !
Jack
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论