MongoDB 查询以存储文件名和位置?
为了存储,让我们看一个示例并创建一个包含文档的集合 −
> db.demo645.insertOne( ... { ... 'fileName' : 'MongoDB Program', ... 'fileLocation':'C:/users/workspace/AllMongoDBProgram/MongoDB Program' ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e9c78f36c954c74be91e6e8") } > > db.demo645.insertOne( ... { ... 'fileName' : 'SumOfTwoNumbers.java', ... 'fileLocation':'E:/eclipseWorkspace/AllJavaPrograms/SumOfTwoNumbers.java' ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e9c78f36c954c74be91e6e9") } > db.demo645.insertOne( ... { ... 'fileName' : 'Script.sql', ... 'fileLocation':'C:/MySQLQuery/Script.sql' ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e9c78f46c954c74be91e6ea") }
使用 find() 方法显示来自集合的所有文档 −
> db.demo645.find();
这将产生以下输出 −
{ "_id" : ObjectId("5e9c78f36c954c74be91e6e8"), "fileName" : "MongoDB Program", "fileLocation" : "C:/users/workspace/AllMongoDBProgram/MongoDB Program" } { "_id" : ObjectId("5e9c78f36c954c74be91e6e9"), "fileName" : "SumOfTwoNumbers.java", "fileLocation" : "E:/eclipseWorkspace/AllJavaPrograms/SumOfTwoNumbers.java" } { "_id" : ObjectId("5e9c78f46c954c74be91e6ea"), "fileName" : "Script.sql", "fileLocation" : "C:/MySQLQuery/Script.sql" }
广告