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" }