是的,请使用getSiblingDB()
。让我们将一些文档添加到数据库-
> use customer_tracker-990; switched to db customer_tracker-990 > db.demo1.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea4697ca7e81adc6a0b3954") } > db.demo1.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea46980a7e81adc6a0b3955") } > db.demo1.insertOne({"Name":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea46984a7e81adc6a0b3956") }
在find()
方法的帮助下显示集合中的所有文档-
> db.getSiblingDB("customer_tracker-990").demo1.find();
这将产生以下输出-
{ "_id" : ObjectId("5ea4697ca7e81adc6a0b3954"), "Name" : "Chris" } { "_id" : ObjectId("5ea46980a7e81adc6a0b3955"), "Name" : "David" } { "_id" : ObjectId("5ea46984a7e81adc6a0b3956"), "Name" : "Bob" }