图2-2-9
2.1.3 Save Mongodb RecordsSave MongoDB Records关键字用来向指定的Collection中保存插入的记录,该关键字接收[ dbName | dbCollName | recordJSON ]这三个参数。
示例:我们向startup_log这个Collection中插入一条记录,如下图2-2-10所示。
图2-2-10
运行结果如下:
Starting test: RobotFrameworkTest1.TestSute13.TestCase004
20180825 22:16:34.333 : INFO :
| Connect To MondoDB | dbHost | dbPort | dbMaxPoolSize | dbNetworktimeout | dbDocClass | dbTZAware |
| Connect To MondoDB | 127.0.0.1 | 27017 | 2 | None | <type 'dict'> | False |
20180825 22:16:34.344 : INFO : | ${allResults} | Save MongoDB Records | local | startup_log | {u'book': u'RobotFramework', '_id': ObjectId('5b8164c2685b132ec4739503')} |
20180825 22:16:34.347 : INFO : | Disconnect From MongoDB |
Ending test: RobotFrameworkTest1.TestSute13.TestCase004
执行完成后,我们通过MongoDB客户端连接到服务端,执行db.startup_log.find()命令来查看startup_log这个Collection下的记录,如下图所示,可以看到{"book":"RobotFramework"}这条数据记录已经成功插入到了
MongoDB中,如下图2-2-11所示。
图2-2-11
2.1.4 Retrieve All Mongodb RecordsRetrieve All Mongodb Records关键字用来获取指定Collection下的所有数据记录,该关键字接收[ dbName | dbCollName | returnDocuments=False ]这三个参数。
示例:我们通过Retrieve All Mongodb Records关键字来获取startup_log下的数据记录,如下图2-2-12所示。
图2-2-12
运行结果如下:
Starting test: RobotFrameworkTest1.TestSute13.TestCase005
20180825 22:38:05.197 : INFO :
| Connect To MondoDB | dbHost | dbPort | dbMaxPoolSize | dbNetworktimeout | dbDocClass | dbTZAware |
| Connect To MondoDB | 127.0.0.1 | 27017 | 2 | None | <type 'dict'> | False |
20180825 22:38:05.213 : INFO : ${allResults} = [{u'hostname': u'yongqing-PC', u'pid': 8964L, u'startTimeLocal': u'Sat Aug 25 17:45:31.203', u'cmdLine': {u'storage': {u'dbPath': u'D:\\MongoDB\\Server\\3.2\\data'}, u'systemLog': {u'path': u'D:\\Mong...
20180825 22:38:05.215 : INFO : [{u'hostname': u'yongqing-PC', u'pid': 8964L, u'startTimeLocal': u'Sat Aug 25 17:45:31.203', u'cmdLine': {u'storage': {u'dbPath': u'D:\\MongoDB\\Server\\3.2\\data'}, u'systemLog': {u'path': u'D:\\MongoDB\\Server\\3.2\\logs\\log.log', u'destination': u'file'}}, u'startTime': datetime.datetime(2018, 8, 25, 9, 45, 31), u'_id': u'yongqing-PC-1535190331203', u'buildinfo': {u'storageEngines': [u'devnull', u'ephemeralForTest', u'mmapv1', u'wiredTiger'], u'maxBsonObjectSize': 16777216, u'bits': 64, u'sysInfo': u'deprecated', u'modules': [], u'openssl': {u'compiled': u'disabled', u'running': u'disabled'}, u'javascriptEngine': u'mozjs', u'version': u'3.2.4', u'gitVersion': u'e2ee9ffcf9f5a94fad76802e28cc978718bb7a30', u'versionArray': [3, 2, 4, 0], u'debug': False, u'buildEnvironment': {u'cxxflags': u'/TP', u'cc': u'cl: Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x64', u'linkflags': u'/nologo /DEBUG /INCREMENTAL:NO /LARGEADDRESSAWARE /OPT:REF', u'distarch': u'x86_64', u'cxx': u'cl: Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x64', u'ccflags': u'/nologo /EHsc /W3 /wd4355 /wd4800 /wd4267 /wd4244 /wd4290 /wd4068 /wd4351 /we4013 /we4099 /we4930 /Z7 /errorReport:none /MT /O2 /Oy- /Gw /Gy /Zc:inline', u'target_arch': u'x86_64', u'distmod': u'', u'target_os': u'windows'}, u'targetMinOS': u'Windows Vista/Windows Server 2008', u'allocator': u'tcmalloc'}}, {u'_id': ObjectId('5b8164c2685b132ec4739503'), u'book': u'RobotFramework'}]
20180825 22:38:05.217 : INFO : | Disconnect From MongoDB |
Ending test: RobotFrameworkTest1.TestSute13.TestCase005
如下图2-2-13所示,运行结果与我们在客户端通过db.startup_log.find()命令行获取到结果是一致的。
图2-2-13
2.1.5 Update Many Mongodb RecordsUpdate Many Mongodb Records关键字用来更新Collection中的数据记录,该关键字接收[ dbName | dbCollName | queryJSON | updateJSON | upsert=False ]这五个参数。
示例1:我们更新上面示例中插入的这条{"book":"RobotFramework"}记录为{"book":"robotFramework"},即将RobotFramework变为robotFramework,如下图2-2-14所示。