Python MongoDB mongo shell读取文件问题

Python MongoDB mongo shell读取文件问题,python,mongodb,pymongo,Python,Mongodb,Pymongo,我正在尝试阅读我在MongoDB中创建的一个集合。如果要读取已创建的数据库,“mongo”的正确shell脚本命令是什么样子的?使用mongo shell获取access数据库 mongo -u jdoe -p mysecretPassword --authenticationDatabase admin --host "myReplicaSet/localhost:28017,localhost:28018,localhost:28019" Mongoshell命令选择数据库上下文并从集合中

我正在尝试阅读我在MongoDB中创建的一个集合。如果要读取已创建的数据库,“mongo”的正确shell脚本命令是什么样子的?

使用mongo shell获取access数据库

mongo -u jdoe -p mysecretPassword --authenticationDatabase admin --host "myReplicaSet/localhost:28017,localhost:28018,localhost:28019"
Mongoshell命令选择数据库上下文并从集合中选择数据

use mydatabase
db.mycollection.find()

我强烈建议您阅读,它可以很好地引导您完成这样的简单操作

您可能会发现本教程中的一些摘录很有用(将localhost替换为mongoDB所在的位置,如果不是本地的话)。当然还有数据库和集合名称

from pymongo import MongoClient
client = MongoClient('localhost', 27017)
collection = client['test-database']['test-collection']

# Insert a test record into your collection
id = collection.insert_one({"a": 1}).inserted_id

# Read the recently inserted record from the collection by ID
post = collection.find_one({"_id": id})
本教程还有其他有用的示例,例如如何执行批量读取/插入以及其他有用的技巧